Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <table>
    <tbody>
      <tr>
        <td>0x0</td>
        <td>0x1</td>
      </tr>
      <tr>
        <td>1x0</td>
        <td>1x1</td>
      </tr>
    </tbody>
  </table>
  <script>
    (function() {
      function handlerAsignment()
      {
        var trs = document.getElementsByTagName("tr");
        var tds;
        var trIndex, tdIndex;
        
        for (trIndex = 0; trIndex < trs.length; ++trIndex) {
          tds = trs[trIndex].getElementsByTagName("td");
          
          for (tdIndex = 0; tdIndex < tds.length; ++tdIndex){
            tds[tdIndex].onclick = buildHandler(trIndex, tdIndex);
          }
        }
      }
      
      function buildHandler(tr, td) {
        return function() {
          atack(tr, td);
        };
      } 
      
      function atack(tr, td) {
        alert("Attack " + tr + "x" + td);
      }
      
      handlerAsignment();
    })();
  </script>
</body>
</html>
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers