How to make a div
clickable using Jquery?
I tried to do the below but nothing happens, why?
$(".delete").on("click", function() {
$(this).closest(".card").remove();
});
})
full code:
$(document).ready(function() {
var num = 0;
$("#add").click(function() {
$("main").append('<div class="card" id="photo' + num.toString() + '" style="width: 20rem;">\
<div class="layer"></div>\
<div class="card-block">\
<h4 class="card-title" id="title' + num.toString() + '"></h4>\
<p class="card-text" id="text' + num.toString() + '"></p>\
</div>\
<div class="card-block">\
<div class="delete">Del</div>\
<div class="edit">edit</div>\
</div>\
</div>');
var title = $("#noteTitle").val();
var body = $("#noteBody").val();
var photo = $("#notePhoto").val();
if (photo) {
$("#photo" + num.toString()).prepend('<img class="card-img-top" src=' + photo + ' alt="Card Image">');
} else {
$(".layer").css({"background-color": "yellow", "position": "absolute", "opacity": ".1", "top":"0", "left":"0", "width": "100%", "height": "100%"});
}
$(".card-title#title"+ num.toString()).html(title);
$(".card-text#text"+ num.toString()).html(body);
$("#noteTitle").val("");
$("#noteBody").val("");
num ++;
});
$(".delete").on("click", function() {
$(this).closest(".card").remove();
});
})