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>
    <tr>
      <td>foo
      <td>bar
      <td><button type="button">baz</button>
    <tr>
      <td>foo2
      <td>bar2
      <td><button type="button">baz2</button>
    <tr>
      <td>foo3
      <td>bar3
      <td><button type="button">baz3</button>
    <tr>
      <td>foo4
      <td>bar4
      <td><button type="button">baz4</button>
  </table>
  
  <script>
    function whatRowAmIIn(event) {
      var target = event.target;
      // Do nothing if something other than a button was clicked
      if (target.tagName.toLowerCase() !== "button") {
        return;
      }
      // Figure out which row the button was in
      var tr = target.parentNode.parentNode;
      // Get the bar td (for the sake of example)
      var bar_td = tr.querySelector('td:nth-child(2)');
      alert(bar_td.firstChild.data); 
    }
    document.querySelector('table').addEventListener('click', whatRowAmIIn);
  </script>
        
</body>
</html>
Output 300px

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers