Get HTML Table Row and RowIndex when Clicked in jQuery

Last Reply 2 months ago By dharmendr

Posted 2 months ago

how can we get row and orw id on row click of html table 

When i click on html table row then i want to fetch all the record of that row and also row number



Posted 2 months ago

Hi SajidHussa,

Check this example. Now please take its reference and correct your code.


<html xmlns="">
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
        $(function () {
            $('#tblCustomers td').on('click', function () {
                var row = $(this).closest('tr');
                var id = $(row).find('td').eq(0).html();
                var name = $(row).find('td').eq(1).html();
                var country = $(row).find('td').eq(2).html();
                alert('Id : ' + id + '\nName : ' + name + '\nCountry : ' + country + '\nRow Number : ' + $(row).index());
    <table id="tblCustomers" style="border: 1px solid #ccc;">
            <td>John Hammond</td>
            <td>United States</td>
            <td>Mudassar Khan</td>
            <td>Suzanne Mathews</td>
            <td>Robert Schidner</td>