Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dustintheweb/9924744 to your computer and use it in GitHub Desktop.
Save dustintheweb/9924744 to your computer and use it in GitHub Desktop.
Event Bubbling, Promises & Triggers - for a clean navigation structure
// in something.html
// <div>
// <a href="" data-page-state="isAbout">lorem ipsum</a>
// </div>
//promises
$('body').on('isAbout', function(){
// do something
});
$('body').on('isNews', function(){
// do something else
});
$('.some-div').on('click', 'a', function(event) {
event.preventDefault();
var state = $(this).data('pageState');
$.section.body.trigger(state);
});
// some-div is a parent to the selector in the on()
// this will target all anchors within that some-div only
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment