views:

80

answers:

1

Here's a Firebug session

>>> var e = $("<div>div-1<p>p-1</p></div><div>div-2</div><p>p-2</p>");
>>> e
[div, div, p]
>>> e.find('div')
[]
>>> e.find('p')
[p]

Isn't e.find('div') and e.find('p') supposed to return [div, div] and [p, p] respectively?

+4  A: 

I think your problem is that it is calling find on each element in the e, since e isn't one whole element. If you wrap e in another tag, ie:

var e = $("<div><div>div-1<p>p-1</p></div><div>div-2</div><p>p-2</script></div>");

then you get the behavior you wanted.

Alternatively if you don't wish to modify e you can use

 e.filter("p").add(e.find("p"));
cobbal