How would I use .on()
if the HTML is not generated yet? The jQuery page says
If new HTML is being injected into the page, select the elements and attach event handlers after the new HTML is placed into the page.
But I'm not really sure how to do that. Is there a way to "reload" the event handler?
So if I had
$(document).ready(function(){
$('.test').on('click', function(){
var id = $(this).attr('id');
console.log("clicked" + id);
});
generatePage();
});
where generatePage() creates a bunch of divs with .test
, how would I rebind .on()
?
I'm aware similar questions have been asked, but I didn't find what I was looking for after a quick search.