Reputation: 458
Is there a way to target only li elements where the a tag has a specific class?
for example:
<li> <a href="#" class="mobile-only">link</a> </li>
<li> <a href="#" class="other-class">link</a> </li>
Can I just target the li where a has class "mobile-only"?
Upvotes: 0
Views: 188
Reputation: 68413
you can access the parent of anchor tag with class mobile-only
$( "a.mobile-only" ).parent();
or you can use parent pseudo selector, but there are performance concerns
li a:parent { background: none; }
js Code $( "li a:parent" )
also the has selector
li:has(a.mobile-only) { background: none; }
js Code $( "li:has(a.mobile-only)" )
Upvotes: 6
Reputation: 1587
This is very easy to do with jQuery.
Just do:
$("a.mobile-only").parents("li")
Upvotes: 0