jQuery - Binding a Handler to Multiple Events


/ Published in: jQuery
Save to your folder(s)

One bind event, multiple events. Handy.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.