0

With reference to this answer for live search through table rows, the answer illustrates how to search through first column with the following statement:

var id = $row.find("td:first").text();

My requirement is to search through second column. Replacing first with second is not working.

Community
  • 1
  • 1
deadbug
  • 434
  • 5
  • 19

2 Answers2

3

You can use eq selector:

var id = $row.find("td:eq(1)").text();

Index starting from 0.


You may also use css selector :nth-child instead. There's no :second or like :third selectors in css. The css selector only accepts :first-child, :last-child selectors and the jQuery utilize them using shorthand :first and the :last selector. So, you can use :first, :last, :first-child, :last-child in jQuery selector.

var id = $row.find("td:nth-child(2)").text();

The :nth-child index starts with 1.

Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
  • Tested both methods. Working Fine. It would be helpful for all if you can give whole code with respect to the referenced question. Cheers ! – deadbug Mar 24 '17 at 08:34
0

Another way to search through cells of 2nd column is to use nth-of-type() CSS selector.

$('td:nth-of-type(2)').each(function(index){
    $(this).text();
})
xhg
  • 1,850
  • 2
  • 21
  • 35