Given: X -> B -> C -> D -> Child
I want jQuery to return all ancestors up to the first node that matches some selector.
jQuery $(Child).parents(X)
will return only X
as opposed to X, B, C, D
. I know I can use parent()
to build this array manually, but is there a better way?
Oops. Found it:
$(Child).parentsUntil(X)
Source: http://api.jquery.com/parentsUntil/