Get Table Row Column Index - Jquery
How to get table row and column index using jquery?
Snippet Code
Use the below jQuery code to get the index of clicked table row and column.
<script type='text/javascript'>
$(function() {
$('td').click(function(){
var column = $(this).parent().children().index($(this));
var rows = $(this).parent().parent().children().index($(this).parent());
alert('Row Index: ' rows ', Column Index: ' column);
});
});
</script>
<p align='center'><b>Get Table Row Column Index</b></p>
<table border="1" align='center'>
<tr><th>S.No</th><th>Product_name</th><th>Product_id</th></tr>
<tr><td>1</td><td>Nestle</td><td>105</td></tr>
<tr><td>2</td><td>Nescafe</td><td>07</td></tr>
<tr><td>3</td><td>Boost</td><td>125</td></tr>
</table>
Tags