get clicked element using jquery on event? -
update 2016-08-31 this closed popular, i'm editing clean things up. original issue had turned out caching problem. have removed question , answers make more sense , have accepted top answer. useful someone.
re: jquery selector click not firing dynamically generated button?
i'm using following code detect when dynamically generated button clicked.
$(document).on("click",".appdetails", function () { alert("test"); }); normally, if did $('.appdetails').click() use $(this) element clicked on. how accomplish above code?
for instance:
$(document).on("click",".appdetails", function () { var clickedbtnid = ?????? alert('you clicked on button #' + clickedbtnid); });
as simple can be
use $(this) here too
$(document).on("click",".appdetails", function () { var clickedbtnid = $(this).attr('id'); // or var clickedbtnid = this.id alert('you clicked on button #' + clickedbtnid); });
Comments
Post a Comment