Advertisement
khangnguyen

event-delegation

Sep 8th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. document.getElementById("myTable").addEventListener("click",function(e) {
  2.   // e.target was the clicked element
  3.   if(e.target && e.target.nodeName == "td") {
  4.     // Get the CSS classes
  5.     var classes = e.target.className.split(" ");
  6.     // Search for the CSS class!
  7.     if(classes) {
  8.       // For every CSS class the element has...
  9.       for(var x = 0; x < classes.length; x++) {
  10.         // If it has the CSS class we want...
  11.         if(classes[x] == "classA") {
  12.           // Bingo!
  13.         }
  14.       }
  15.     }    
  16.   }
  17. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement