Specifically, I want to say: for elements whose class value doesn't contain this element's ID value, execute this function.
For example, clicking #foo
will execute fadeOut()
on the list items whose classes don't contain .foo
in the following HTML:
<button id="foo">foo</button>
<button id="bar">bar</button>
<button id="baz">baz</button>
<ul>
<li class="foo">Lorem</li>
<li class="foo bar">Ipsum</li>
<li class="baz">Dolor</li>
</ul>
So upon clicking #foo
, the last list item should disappear, since the first two both contain the .foo
class.
Try
$('button').on('click', function(){
$('li:not(.'+this.id+')').fadeOut();
});
Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With