undelegate.html 715 B

12345678910111213141516171819202122232425262728293031
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Undelegate</title>
  6. </head>
  7. <body>
  8. <!-- 1. Write some markup -->
  9. <ul>
  10. <li><button>Item 1</button></li>
  11. <li><button>Item 2</button></li>
  12. <li><button>Item 3</button></li>
  13. <li><button>Item 4</button></li>
  14. <li><button>Item 5</button></li>
  15. </ul>
  16. <!-- 2. Include library -->
  17. <script src="../dist/delegate.js"></script>
  18. <!-- 3. Remove event delegation -->
  19. <script>
  20. var ul = document.querySelector('ul');
  21. var delegation = delegate(ul, 'li button', 'click', function(e) {
  22. console.log(e.target);
  23. });
  24. delegation.destroy();
  25. </script>
  26. </body>
  27. </html>