Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting td by index with jQuery

People also ask

How to get td index using jQuery?

You can use the index() with parentsUntill() to the parent TR element of that TD.

How to get index element in jQuery?

The index() is an inbuilt method in jQuery which is used to return the index of the a specified elements with respect to selector. Parameter: It accepts an optional parameter “element” which is used to get the position of the element. Return value: It returns an integer denoting the index of the specified element.

How to get row index for td in JavaScript?

I can get the row index by using this code: var row = $(this). parent(). parent(); var rowIndex = $(row[0].

How do I get the values of columns for a selected row using jQuery?

btnSelect',function(){ // get the current row var currentRow=$(this). closest("tr"); var col1=currentRow. find("td:eq(0)"). text(); // get current row 1st TD value var col2=currentRow.


With plain JavaScript:

// table is a reference to your table
table.rows[rowIndex].cells[columnIndex]

Reference: HTMLTableElement, HTMLTableRowElement


With jQuery, you could use .eq():

$('#table tr').eq(rowIndex).find('td').eq(columnIndex)
// or
$('#table tr:eq(' + rowIndex + ') td:eq(' + columnIndex + ')')

How about using the nth-child selector?

http://api.jquery.com/nth-child-selector/

var row = 4;
var col = 2

var cell = $('table#tableId tr:nth-child(' + row + ') td:nth-child(' + col + ')');

Note that the child index is 1-based, rather than the more usual 0-based.