Options for jQuery's on and dynamically added html -
i'm using jquery's on method bind button click events event. i'm using css class assignment.
$('.removebtn').on('click', function () { //code execute on click here });
when page loads, buttons class "removebtn" bound accordingly , work without problem.
i dynamically add buttons after page has loaded. these have class "removebtn", not fire.
i add these new button's click event handler existing predefined handler, can't find examples of how this.
all examples have found want add function event handler @ creation. seems fine simple alert or call, have ajax call , string parsing , validation. don't want repeat code again.
i tried adding function call both places, required duplication too.
i'd way create new button , tell user function defined in code shown above.
what options?
you need use event delegation
$(document).on('click','.removebtn', function () { //code execute on click here });
Comments
Post a Comment