Jquery finding the first P

jquery

I have the following:

$(content).filter("p:first").text();

where content =

<div><div><div><p>adsdas</p><p>dsa</p><p>dsa</p><p>dsa</p></div><p>&nbsp;</p><p>asdadsadsads</p></div><p><br></p><p><br></p><p>asd</p><p><br></p><p><br></p></div>

What I want to happen is to find the first PARAGRAPH tag, whether it be at the top or down a child level or more of a div. How can I tell jQuery to find the first

tags all the way down until the first match?

Thanks

Best Solution

You can use .find() to get any level decendant, like this

$(content).find("p:first").text();

If it may be the top level, it's not as clear, you need to do .filter() and .find()...but the results are in order, so still take the first, like this:

$(content).find("p").andSelf().filter("p:first").first().text();