tags:

views:

41

answers:

4

As per this page says:

Find all parent elements of each span that is a paragraph.

How to get the first one that matches?

+1  A: 
$("span").parents("p:first")
Brandon H
+1  A: 

jQuery returns such results in an array. Have you tried using [0] after the query. $("span").parents("p")[0]. This would give the first parent.

theraneman
+1  A: 

If you mean by first parent the one that is closest to the element, you can use Traversing/closest:

$(selector).closest('p');
CMS
good psychic abilities. (this doesn't answer the question, but is what the asker wanted)
Brandon H
Yeah, LOL, I mis-readed the question and actually was about to delete...
CMS
Haha.. thats funny. +1 for ESP
Doug Neiner
A: 

$("span").parents("p :first")

TheVillageIdiot