try the following:
$(".item-card").click(function() {
var itemnume = $(this).find("img").attr("title");
var replaced = itemnume.split(' ').join('_');
if ($(this).hasClass('selected-item')) {
console.log()
$("#" + replaced).remove();
} else {
$("#itemcart").append($("<div id=" + replaced + ">" + itemnume + "</div>"));
}
$(this).toggleClass("selected-item");
});
40
solved Javascript to check if div has child with that classname [closed]