Click on HTML table and get row number (with Javascript, not jQuery) Click on HTML table and get row number (with Javascript, not jQuery) javascript javascript

Click on HTML table and get row number (with Javascript, not jQuery)


Try this:

function  getId(element) {    alert("row" + element.parentNode.parentNode.rowIndex +     " - column" + element.parentNode.cellIndex);}
<table>  <tr>    <td><input type="button" value="button" onclick="getId(this)"></td>    <td><input type="button" value="button" onclick="getId(this)"></td>    <td><input type="button" value="button" onclick="getId(this)"></td>  </tr>  <tr>    <td><input type="button" value="button" onclick="getId(this)"></td>    <td><input type="button" value="button" onclick="getId(this)"></td>    <td><input type="button" value="button" onclick="getId(this)"></td>  </tr>  <tr>    <td><input type="button" value="button" onclick="getId(this)"></td>    <td><input type="button" value="button" onclick="getId(this)"></td>    <td><input type="button" value="button" onclick="getId(this)"></td>  </tr></table>