In jQuery you can call closest to find the closest parent.
If I have a a in a li in a ul in a td in
You can list multiple element selectors to the closest function, it will only find the closest of one of them:
$('a').closest('table, ul')
Example:
$(document).on("click", function( event ) {
$(event.target).closest("li, b").toggleClass("hilight");
});
.hilight{
background: rgba(255, 0, 0, 0.5);
}
- Click me!
- You can also click this line or click me!