AddyProg
AddyProg

Reputation: 3050

Finding a specific child div via jquery

I am trying to find and append some text in a dynamically created parent div but its not working. 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 Fiddle: http://jsfiddle.net/xBB5x/10166/

Upvotes: 4

Views: 69

Answers (1)

Ahs N
Ahs N

Reputation: 8366

Change this:

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

to this:

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

Here is the JSFiddle demo

Upvotes: 6

Related Questions