Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to select n-th td of a tr using jquery

How can I select nth < td > of a < tr > using jquery. Say, I want to select 3rd < td >. I have id for every tr. How can we achieve this ?

like image 753
Shades88 Avatar asked Aug 29 '11 10:08

Shades88


People also ask

How can get TD of TR in jQuery?

jQuery(". dname"). find("tr td:eq(1)"). val();

How to select nth element in jQuery?

jQuery :nth-of-type() SelectorThe :nth-of-type(n) selector selects all elements that are the nth child, of a particular type, of their parent. Tip: Use the :nth-child() selector to select all elements that are the nth child, regardless of type, of their parent.

How to get the nth child of an element in jQuery?

jQuery :nth-child() Selector The :nth-child(n) selector selects all elements that are the nth child, regardless of type, of their parent. Tip: Use the :nth-of-type() selector to select all elements that are the nth child, of a particular type, of their parent.

How can get current TR data in jQuery?

$(this). closest('tr'). children('td:eq(0)'). text();


2 Answers

using :nth-child() Selector

like

$("tr td:nth-child(2)") 
like image 200
Haim Evgi Avatar answered Sep 26 '22 03:09

Haim Evgi


the eq api should do this for you

$("table td").eq(n) 
like image 38
user917670 Avatar answered Sep 24 '22 03:09

user917670