Finding a specific child div through jquery

I am trying to find and add some text to a dynamically created parent div but it does not work. Here is what I have tried.

var mainDiv = "" +
"<div>" +
    "<div></div>" +
    "<div>" +
        "<div class='image-here'></div>" +
    "</div>" +
"</div>"; // proper script is in Fiddle

var imageDiv = $(mainDiv).children(".image-here");
$(imageDiv).html("text allocated");
$(mainDiv).dialog();

Here is the script: http://jsfiddle.net/xBB5x/10166/

+4
source share
1 answer

Change this:

var imageDiv = $(mainDiv).children(".image-here");
$(imageDiv).html("text allocated");
$(mainDiv).dialog()

:

$(mainDiv).dialog().find(".image-here").html("text allocated");

Here is the JSFiddle daemon

+6
source

Source: https://habr.com/ru/post/1619797/


All Articles