I’m using the closest method to find an attribute within a div:
.closest($('div[my-attribute]'));
The attribute could also exist within an li element:
.closest($('li[my-attribute]'));
What is an elegant way of finding the attribute within the ‘li’ if it is not found in the div?
Something like:
var closest = myDiv.closest($('div[my-attribute]'));
if(closest == null){
closest = myDiv.closest($('li[my-attribute]'));
}
This will return the closest of parents containing the attribute “my-attribute”, regardless of weather the element is div, li (or anything else).