Posted By

1man on 03/12/09


Tagged

event jquery namespace


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

gtalmes


jQuery event namespace


 / Published in: jQuery
 

Adding a namespace to an event can make it easier to unbind. It is very easy to unbind all events with the same namespace.

  1. //Bind Event One
  2. $("a").bind("click.nameOne", function(){
  3. console.log("Event One Fire!");
  4. return false;
  5. });
  6.  
  7. //Bind Event Two
  8. $("a").bind("click.nameTwo", function(){
  9. console.log("Event Two Fire!");
  10. return false;
  11. });
  12.  
  13. //Unbind all nameTwo events
  14. $("a.utwo").click(function(){
  15. $("a").unbind(".nameTwo");
  16. });
  17. //Unbind all nameOne events
  18. $("a.uone").click(function(){
  19. $("a").unbind(".nameOne");
  20. });

Report this snippet  

You need to login to post a comment.