first post here. I am new to jquery and I came across some sort of gray area. I hope I find my answer here and learn from him :)
So, I mean 10 different divs. Everyone has the same class. And every time I click on the div, it should add another class (in this case background-color in css). For this, I have this:
$(document).ready(function() {
$(".menucardmenu").click(function(){
if($(this).hasClass("menucardmenu")) {
$(this).addClass("backgroundmenucard");
}
else {
alert ("condition false");
}
});
});
But the question is, how can I make sure that only one div can have this background color (in my case, backgroundmenucard). Depending on which div the user clicks, this div will have a background color, and the previous div (which was pressed) should reset back to normal. Can I do it with this right ?:
$ (this) .removeClass ("backgroundmenucard");
Does anyone know the answer to this question?
Regards, Andrew