I know this is an old question but I thought it deserved an answer so here you go:
There are a couple of ways to go about this (it's a bit of a broad question so here is a bit of a broad answer):
FIRST WAY:
// This is in plain JS, but the jQuery equivalent is:
// document.on('click', '#my-id, function(e) { /* Function stuff */ });
document.addEventListener('click' function(e) {
if (e.target.id === 'my-id') {
// Function stuff
}
});
The benefit of doing it this way is that you never have to remove an event listener, as there will always be a document. You could even set up a system of "stages" (I call them stages, I don't know if there is a better word for them) by using classes, i.e. your navigation links all have the class nav-item
and in your event listener you could have this code:
// jQuery equivalent of if statement is: if ($(this).is('nav-item')) {}
if (e.target.className.match(/nav-item/)) { // You could also use .include(), etc.
switch(e.target.id) {
case 'item1':
loadPageOneFunction(); // Or whatever
break;
case 'item2':
loadPageTwoFunction(); // Or whatever
break;
}
}
SECOND WAY
// Note how I named the function
document.getElementById('my-id').addEventListener('click', function clickFunction(e) {
myAjaxFunction(e.target); // Or whatever
});
// Later...
if (pageToLoad === 'page2') {
// You are required to name the function you are removing.
document.getElementById('my-id').removeEventListener('click', clickFunction);
document.getElementById('my-page2-id').addEventListener('click', clickFunction);
}
I honestly prefer the first way as it is less code, I can use nameless functions (anonymous functions) - I know, big deal, but still...
There is a third way, which is just to not worry about removing the event listeners. You can read about that here.
Again, this is a very broad answer as its a broad question.