Then delegate it to activity
since that is the one that doesnt seem to change. Your ajax call overwrites activityPaganation
again so the event binding on that doesn't get persisted.
$("#activity").on("click", "li a", function(e) {
e.preventDefault();
var pid = $(this).text();
alert('1234567');
/*$.post("ajax.php", {aid:1,page:pid}, function(response) {
$("#activity").html(response);
alert(pid);
});*/
});
Here is the basic principle of event delegation, You bind the event to the container that exists in DOM as long as you need the event or the document head(worst case). Any click happening on its descendants gets bubbled up to the parent (where you bound the event to) which then jquery looks for the selector match (for the selector you provided int he filter in the on
syntax) and if it originated from that selector it executes the handler.
Also note that with your current registration of event, the first event registration should not work since load is async, your event registration part executes before load is completed.