Acccess nth:tr or nth:td of table in Jquery | Techbirds

Some times we got a situation in which we have to access some specific table row

of the table. We can achieve this through Jquery.

To access nth row

Some Text Here

$(‘#firstTable tbody tr:nth-child(3).html(‘

Some Text Here

To access nth table data

of table

$(‘#first_Table tbody tr).find(‘td:nth-child(2)’);

$(‘#first_Table tbody tr).find(‘td:nth-child(2)’);

To access each row of table

var rowCount = $(‘#first_Table tr’).length; //will count number of rows in table var i = 1; $(‘#first_Table tr’).each(function() { $(‘#first_Table tbody tr:nth-child(‘+i+’)’).find(‘td:eq(3)’).append(‘Some Text Goes Here’); i = i+1; });

var rowCount = $(‘#first_Table tr’).length; //will count number of rows in table

var i = 1;

$(‘#first_Table tr’).each(function() {

$(‘#first_Table tbody tr:nth-child(‘+i+’)’).find(‘td:eq(3)’).append(‘Some Text Goes Here’);

i = i+1;

});

Count number of columns in HTML table

$(function() { var colCount = 0; $(‘tr:nth-child(1) td’).each(function () { if ($(this).attr(‘colspan’)) { colCount += +$(this).attr(‘colspan’); } else { colCount++; } }); });

$(function() {

    var colCount = 0;

    $(‘tr:nth-child(1) td’).each(function () {

        if ($(this).attr(‘colspan’)) {

            colCount += +$(this).attr(‘colspan’);

        } else {

            colCount++;

        }

    });

});

5,577 total views, 8 views today

Share this Onfacebook-3390251twitter-1921902linkedin-9911568google-4010339