Reputation: 12475
i have a div:
<div id="div"></div>
with
$("#div").append("<div id='c'></div>")
$("#c").length
returns 0. what i can do for find the div width id = c after inserted in div #div?
thanks
Upvotes: 2
Views: 127
Reputation: 4435
First off, he div won't have a width until it contains some content. Try that.
Upvotes: -1
Reputation: 630587
What you have will work as long as you're running it in a document.ready
handler, like this:
$(function() {
$("#div").append("<div id='c'></div>")
alert($("#c").length ); //alerts 1
});
You can test it here, without the .ready
wrapper, if it runs before <div id="div"></div>
is loaded in the DOM, that #div
selector won't find anything, and so it won't append anything to the 0
elements it found.
Upvotes: 1
Reputation: 68026
It does work for me: http://jsfiddle.net/4Q4cM/
Maybe #div
element isn't appended to DOM tree itself? E.g., you're doing $('<div id="div"></div>')
instead of inserting it in the document. Nick Craver also has a good guess.
Upvotes: 2