Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery.find() ignores root node

My jQuery object looks like this:

var myJq = jQuery("<div class='a'></div><div class='b'></div>")

myJq.find(".a") returns an empty jQuery object, apparently because find() searches only the children of the nodes contained in a jQuery object, not the nodes themselves.

How can I grab one of the divs in myJq using a selector?

like image 910
morgancodes Avatar asked Sep 03 '10 15:09

morgancodes


1 Answers

You need to use .filter() instead.

This will filter through items at the top level of the jQuery object.

myJq.filter(".a")
like image 54
user113716 Avatar answered Oct 28 '22 19:10

user113716