[jQuery] How to get the first matching parent of each element?
Dear jQuery collective,
My jQuery foo is failing me, is there an elegant way to return the
_first_ matching parent of each element in a collection?
For example on this test page, I would like
http://mqlx.com/~willmoffat/learn_feature/jquery/first_parent.html
* a list of parent .containers that contain .clickables
* but not the top-level .container since that doesn't directly contain
a .clickable
$('.clickable').parents('.container') - fails the 2nd condition
$('.clickable').parents('.container:eq(0)') - fails the 1st condition
It seems like I need a new function firstParent()
$('.clickable').firstParent('.container')
Or am I missing something obvious?
regards,
--Will