Possible Duplicate:
Check event.target.parentElement with matchesSelector js
I have a dom object, I'd like to match its parents, all parents, against a selector, like querySelectAll()
, but for parents instead of children. Similar to jQuery's .parents('selector')
method, but I do NOT need any back-wards compatibility. Also, no libraries please. I will totes take a boolean return value.
I CAN write this myself as a recursive function/for/while using matchesSelector()
. I'm looking for little-known methods or more efficient code.
Saving any processing is worth it. Think tens of thousands of match checks, or more even.
for(x=0;x<parents.length;x++){if(parents[x].matchesSelector('selector')){return:true;}}
– TurnbuckleElement::closest
– Snowshed