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

JavaScript

Avatar of undefined
Last Comment
James Lopez

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Norie

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
James Lopez

ASKER
Thanks sir..
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck