I am using the rowIndex property of TR but it is not working. Please let me know if i am doing something wrong here.
function myMethod(){
alert ( this.parent.rowIndex ); // parentNode is also used
}
Html
<table border="1">
<tr>
<td onclick="myMethod();">1.1</td>
<td>1.2</td>
<td>1.3</td>
</tr>
<tr>
<td onclick="myMethod();">2.1</td>
<td>2.2</td>
<td>2.3</td>
</tr>
<tr>
<td onclick="myMethod();">3.1</td>
<td>3.2</td>
<td>3.3</td>
</tr>
<tr>
<td onclick="myMethod();">4.1</td>
<td>4.2</td>
<td>4.3</td>
</tr>
</table>
the "this" in this.parent.rowIndex is the window. Not the td element. Try
<td onclick="myMethod(this);">1.1</td>
function myMethod(obj){ alert ( obj.parentNode.rowIndex );}
How about like this?
<td onclick="myMethod(this);">1.1</td>
...
function myMethod(obj){
alert ( obj.parentNode.rowIndex ); // parentNode is also used
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With