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
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.
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.
First off, he div won't have a width until it contains some content. Try that.
length() property (in this case the 'length' is basically the number of elements found by the selector), whereas you seem to be confusing it with width.$("#div #c")
will find what you're looking for
#id in almost every case. In this case it's not the issue.