Posted By

Meander365 on 09/28/10


Tagged

javascript event jquery FAV cookbook


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

bobbym245
LeeRJohnson
wirenaught


jQuery - Binding a Handler to Multiple Events


 / Published in: jQuery
 

One bind event, multiple events. Handy.

  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <script type="text/javascript" src="../assets/js/jquery.js"></script>
  6.  
  7. <script type="text/javascript">
  8.  
  9. $(function () {
  10.  
  11. $('.box').bind('click mouseover', function(e){
  12. alert('event');
  13. });
  14.  
  15. })
  16. </script>
  17. </head>
  18. <body>
  19. <style type="text/css">
  20. .box {width:50px;height:50px;display:block;background:red;margin:20px;border:1px solid #ccc;}
  21. </style>
  22. <a href="#" id="animate">Animate</a>
  23. <div class="box"></div>
  24. <div class="box"></div>
  25. </body>
  26. </html>

Report this snippet  

You need to login to post a comment.