Reputation: 1599
I'm trying to make the click event work for a list of dynamically added buttons.
See this jsfiddle: https://jsfiddle.net/jeffxiao/u1dc57za/5/
the failing line is:
$(".run").on('click', 'ul#mitigationList', clickFunction);
Any feedback is welcome.
Upvotes: 0
Views: 74
Reputation: 971
try this:
$("html body").on('click', '.run', clickFunction);
jsfiddle: https://jsfiddle.net/u1dc57za/12/
Upvotes: 0
Reputation: 6959
This issue is that $('.run').on('click', 'ul#mitigationList', clickFunction)
will look for clicks on ul#mitigationList
descendants of .run
elements which isn't what you want.
Think of it like this:
$('elementsToWatch').on('eventName', 'descendants', functionToRun)
Have updated your fiddle:
https://jsfiddle.net/u1dc57za/11/
Upvotes: 1
Reputation: 1049
Use this click event code :
$(document).on("click", ".run", function(){
alert("Clicked!");
});
Working jsfiddle : https://jsfiddle.net/rajnikpatel/76nmazcf/
Upvotes: 1