0

I have a table as below

ID Name
1  David
11 John

I want to get the row has id = 1:

var row1 = $(this).closest("tr").nextAll("tr").has("td:eq(0):contains(1)");

but the output returned two rows. How do I get the exact value?

PeaceInMind
  • 1,147
  • 3
  • 11
  • 32
  • by `id`, I assume you don't really mean the html element id? – Fabricator Jun 16 '14 at 17:36
  • What does your table's markup look like? What is `this` in the context of your script? – ajm Jun 16 '14 at 17:36
  • tldr: (for duplicate,) use .filter with a custom method that returns true or false based on whether or not the tr should be returned. The id you are filtering by should probably be a data attribute on the TR which would make this far easier. – Kevin B Jun 16 '14 at 17:38
  • @ajm: this is a grid. – PeaceInMind Jun 16 '14 at 17:43
  • @KevinB: I know that can use filter to implement it, but I cannot implement to filter follow td. Please help me. – PeaceInMind Jun 16 '14 at 17:44
  • yes you can. please explain why you cant? – Kevin B Jun 16 '14 at 17:45
  • @KevinB: I'm implementing as below: var row1 = $(this).closest("tr").nextAll("tr").filter(function() { // To do }); I don't know implement to get the row has id = 1 – PeaceInMind Jun 16 '14 at 17:47
  • 1
    Your requirement is that the first cell contain the exact text "1" correct? that's pretty basic with jQuery. http://pastebin.com/KMH4zTP9 Select the first cell of the current row, get it's text, and compare the text to your target id. – Kevin B Jun 16 '14 at 17:48

0 Answers0