I've read 3 answers to similar questions, but I wasn't able to apply them to my site. I'm loading html pages through ajax. I understand I can't apply a $("a").click() event during document.ready because the ajax content links don't exist in the dom yet. I thought about trying to add the events in the $.get response, but adding a $.get to a click inside a $.get seems like madness. My attempts to use $(document).on('click', 'a', fn()) are also not working.
$(document).ready(function() {
$(document).on('click', 'a', function(e) {
e.preventDefault();
$.get($(this).attr("href"), function(data) {
$("#mainSection").html(data);
});
return false;
});
});
mainSection is a div id on index.html (same where this code is running). All links are processing as if normally clicked, with no script errors.