Add a Click Event to elements added to the DOM
Posted
by
E7AD
on Stack Overflow
See other posts from Stack Overflow
or by E7AD
Published on 2012-08-31T15:31:33Z
Indexed on
2012/08/31
15:38 UTC
Read the original article
Hit count: 143
JavaScript
|jQuery
var myOP = '<div>';
for (var i = 0; i < op.length; i++) {
myOP += '<div>';
myOP += '<div id="myBTN-' + [i] + '">' + op[i]['Field1'] + '</div>';
myOP += '<div id="blah-' + [i] + '">' + op[i]['Field2'] + '</div>';
myOP += '</div>';
}
myOP += '</div>';
$("#myBTN-" + i).click(function () {
$('#blah-' + i).toggle("slow");
});
$('#container').html(myOP);
I'm trying to get the click function to fire on the elements i'm created w/ the above for loop. Can anyone point me in the right direction?
© Stack Overflow or respective owner