dimanche 8 février 2015

jQuery not detecting events on dynamically added elements


Vote count:

0




This is driving me insane. It seems like it would be so simple but I've been going at this for days now and I can't figure it out. JSFiddle


All I'm doing is adding an image dynamically, then trying to handle the click event on these dynamically added elements.


Here is the JS because SO wants it:



$(document).ready(function () {

var index = 1;
$('.add-button').click(function () {
addButton();
});

function addButton() {
var html = '<img src=\"http://ift.tt/1xPApr1\" class=\"remove-button_' + index + '\">';
$('.image-list').append(html);
index++;
}

$('.image-list').on('click','remove-button_1', function () {
console.write("hello");
alert("hello");
});
});


asked 47 secs ago







jQuery not detecting events on dynamically added elements

Aucun commentaire:

Enregistrer un commentaire