I think this should be a pretty common jquery function but I just couldn't find anything about it.
say I have 10 divs and each div trigger an event when clicked. So when I cilck a div, jquery adds a class, say "clicked" to the div. But how can I set it so when I click another div, it removes the previous div class "clicked" and gives it to the div that I just clicked?
Thanks!!!
$("div.groupname").click(function() {
$(this).addClass("clicked").siblings().removeClass("clicked");
});
or:
$("div.groupname").click(function() {
$(this).siblings().removeClass("clicked").end().addClass("clicked");
});
You can try it here.
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