I know this has been asked before but I can't seem to figure out what I'm doing wrong.
I am just trying to create some dynamic elements and then attach an event to them using only JQuery. The buttons should launch an alert.
$(function(){
$('#add').on("click",function(){addItem()});
function addItem() {
var listItem = '<li>' + '<button class="checkBtn"></button>' + '<button class="crossBtn"></button>' + '</li>';
$('ul').append(listItem);
}
$('.crossBtn').on("click", function() {
alert() // Doesn't alert why not?
});
$('.checkBtn').on("click", function() {
alert();// Doesn't alert why not?
})
});
Thank you.
;s missing in your code. You should be careful, this will probably cause problems in the future.