So,
How to check with JavaScript if DIV has that classname? Here's an example HTML
<div class="cart"></div>
that would be the parent and then JavaScript creates under that div's upon a click, but if it's already there and you click the item then it's just going to remove it. Example: Button is yellow and if you click it, it add's item to the cart and changes button class to selected. If you click it again, it will remove selected class and also remove item from the cart. I do have a code for the clicking part and adding it to cart, but not for removing it.. How could I do it?
JavaScript
$(".item-card").mousedown(function() {
$(this).toggleClass("selected-item");
var itemnume = $(this).find("img").attr("title");
$("#itemcart").append($("<div id="+itemnume+">"+itemnume+"</div>"));
});
Here it adds the item to the cart, but if you would reclick it, it will do it again. I've tried write a function, which checks that is the item already in cart, if it is then remove it, if not then add it, but I never succeed. I think that would solve my problem though.