I have some code where I add a button dynamically to the page.
<a href=“#1" class="btn btn-default next">Next</a>
I am using the .on() method with the selector parameter but nothing is happening when I click the button. I saw that other people had a similar problem for dynamically added elements but they were missing the selector and adding it solved it.
$(".next").on("click", ".next", function() {
alert(“next page");
});
I've put the button in the main body of my page when it loads and it works fine. It just doesn't work when it gets added to the page later.