Saturday, 15 March 2014

Does jQuery selector work on selector that appears after Javascript code? -



Does jQuery selector work on selector that appears after Javascript code? -

this question has reply here:

events triggered dynamically generated element not captured event handler 5 answers

i have javascript code supposed stuff on click, isn't doing anything. it's button on pane slides in. when click button, expect happen. button, though, populated when ajax phone call completes because ajax phone call fetching html contains button.

here's code set button:

$("#btn-delete-setup").on("click", function() { console.log("clicked"); _deletefunction(); //return false; });

because javascript loaded before pane , button rendered ajax call, mean button not respond .on("click") code? button not responding because when javascript loads, hasn't found button bind to?

so, reply of question : no, code won't work if element appended after script loaded (e.g. on document ready).

but can accomplish jquery :) :

$(document).on("click","#btn-delete-setup", function() { console.log("clicked"); _deletefunction(); //return false; });

full solutions offered on post (duplicate): using jquery 'click' function loaded ajax content?

javascript jquery html ajax

No comments:

Post a Comment