Skip to content

Instantly share code, notes, and snippets.

@elijahmanor
Created August 2, 2010 19:46
Show Gist options
  • Save elijahmanor/505197 to your computer and use it in GitHub Desktop.
Save elijahmanor/505197 to your computer and use it in GitHub Desktop.
//Using Namespaced Events
//When writing jQuery Plugins it is helpful to add a namespace when binding to native or custom events.
//You can unbind all events associated with your plugin without affecting other events.
//The namespace will not affect triggering custom events. They will work as you would expect.
//Use a namespace with your plugin events
$("div").bind("click.myPlugin", func1);
$("div").bind("keydown.myPlugin", func2);
$("div").unbind(".myPlugin");
//Custom events will trigger across namespaces
$("div").bind("aCustomEvent.myPlugin", func1);
$("div").bind("aCustomEvent.yourPlugin", func2);
$("div").trigger("aCustomEvent");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment