html - How to use Jquery to add click function for run time added image? -


i have html table markup generated on browser when user click. here code

$('#selectedtable > tbody:first').append(     '<tr > ' +         '<td>chair</td>' +         '<td><img src="/content/images/showinfo.png" title="show info"></td>' +     '</tr>'     ); 

so question possible add click event above generated image?

yes, can either add onclick handler after added image dom, with

$("#my-image").click(function() {      alert("i've been clicked"); }); 

(for image id my-image)

or can set handler applied future added elements:

$(document).on("click", ".image-class", function() {      alert("i've been clicked"); }); 

(for images classes .image-class)


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -