Suppose I want to implement a simple EventBus pattern in javascript using jQuery. The page has a div where I load some dynamic content using $().load(). This content has some javascript code which subscribes to some events on $(document).ready()
page1.html:
$(document).ready(function() {
$eventBus.on("next", function() {
// do something
});
});
root.html
$("#content").load("page1.html"); // load page1 and invoke it's javascript
How should I properly unsubscribe this event handler when another content with other script is loaded in the same div? I.e. where is the best place to put $eventBus.off("next");
What I am really want to achieve is to make inner pages subscribe to some events on load and unsubscribe on unload