I am trying to lookup elements within a dynamically created element. For some reason this fails. Why does the following return "0"? How to fix this?
alert($('<p id="aa">xxx</p>').find("#aa").length);
I am trying to lookup elements within a dynamically created element. For some reason this fails. Why does the following return "0"? How to fix this?
alert($('<p id="aa">xxx</p>').find("#aa").length);
.find() looks inside the child elements of the currently selected element.
Description: Get the descendants of each element in the current set of matched elements, filtered by a selector.
In this case, there are no nested elements, only text.
$('<p id="aa">xxx</p>').find("#aa") // looks inside the element you're holding
you want to filter based on the elements in your existing collection:
$('<p id="aa">xxx</p>').filter("#aa")
and thus
alert( $('<p id="aa">xxx</p>').filter("#aa").length );