[Solved] Javascript to check if div has child with that classname [closed]


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");
});

https://jsfiddle.net/0tusd19b/

40

solved Javascript to check if div has child with that classname [closed]