<ul>
<li><a href="#">item 1</a></li>
<li><a href="#">item 2</a></li>
<li><a href="#">item 3</a></li>
</ul>
On click, I'd like to addclass active
to the parent li element while also removing the active
class from any other element which may be active already.
$("li a").click( function() {
$(".active").removeClass("active");
$(this).parent("li").addClass("active");
});
$('div.filter').delegate('a', 'click', function (event) {
var theLi = $(this).closest('li');
theLi.siblings('.active:first').removeClass('active');
theLi.addClass('active');
$('ul.items li').hide().filter('.' + this.href.slice(this.href.indexOf("#") + 1)).show();
event.preventDefault();
});
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