I am trying to figure out if it is possible to select elements on a page where the element itself OR a parent element (at any level) has a certain class.
Explained in more detail:
Base function:
- $(SELECTOR).each(function() {
- Do something;
- });
Example html:
- <ul>
- <li>A</li>
- <li class="y">B
- <ul id="1">
- <li id="2">1</li>
- <li id="3">2</li>
- <li id="4">3</li>
- </ul>
- </li>
- <li id="5" class="y">C</li>
- </ul>
The selector would search for elements with either itself having class y or a parent element at any level with the class y. So from the code above the elements with id 1,2,3,4 and 5 would be selected.
Any help appreciated.