Link to home
Start Free TrialLog in
Avatar of James Lopez
James Lopez

asked on

Obtain Row Index on a table

Hello, I want to get RowIndex on a td using buttons within a table. Is there any body can correct my code?

!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Page Title</title>
</head>
<body>
	<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<table id="myTable" style="background: #F0FFFF">
	<tr>
    	<td>
        	Ernesto
            <button>RowIndex</button>
        </td>
        <td>Tyson</td>
    </tr>
	<tr>
    	<td>
        	James
            <button>RowIndex</button>
            </td>
        <td>Tejada</td>
    </tr>
	<tr>
    	<td>
        	Mike
            <button>RowIndex</button>
            </td>
        <td>Arnaiz</td>
    </tr>
</table>
	<script>
      $('#myTable').on('click touchstart', 'button', function (e){
          alert(this.parentElement.rowIndex)
          e.preventDefault();
});
    </script>
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of James Lopez
James Lopez

ASKER

Thanks sir..