How to iterate over specific rows of a table

I have a table, and I have a jQuery object that represents one of the TDs in the table.

I want to be able to scroll through all the rows in the table, starting from the next row from the row that jQuery'd TD is in, to the end.

So, if I have a table like this:

<table> <tr><td>A</td><td>B</td><td>C</td></tr> <tr><td>D</td><td>E</td><td>F</td></tr> <tr><td>G</td><td>H</td><td>I</td></tr> <tr><td>J</td><td>K</td><td>L</td></tr> <tr><td>M</td><td>N</td><td>O</td></tr> <tr><td>P</td><td>Q</td><td>R</td></tr> </table> 

And suppose I have a jQuery object representing td with H in it:

 var theTD = $(...the H cell...); 

In this case, I would like to skip the last three lines.

So there is a good jQuery piece that would give me the equivalent:

 theTD.nextRow_to_lastRow.each(... 
+4
source share
6 answers

With ilan, I got there at the end:

 theTD.parent().find("~ tr").each( 

Other answers will do the job, but above what I was looking for

0
source

Something like that?

 var td = $('td:contains("H")'); var tr = $('tr').length; for(i= td.parent().index()+1; i < tr;i++){ $.each($('tr:eq('+i+') td'),function(){ console.log($(this).text()); }); } 

Mark the demo in the console

+1
source

I think you are after something like this:

 $('td').filter(function() { return $(this).text() == 'H'; }).parent().nextAll().each(function() { console.log(this); }); 

Which will give you the lines:

 <tr><td>J</td><td>K</td><td>L</td></tr> <tr><td>M</td><td>N</td><td>O</td></tr> <tr><td>P</td><td>Q</td><td>R</td></tr> 
+1
source
 var all_td_in_a_table = $("#table-id td") 

and then run it through for or foreach and find h / div / text or whatever you want

0
source

Your situation is rather complicated, and I could not fully understand it; hope this helps: using

  var rows = $("#tableid tr td"); 

you will have the whole cell. Now you can go through each of them and check the value or text. foreach in jquery:

  $(rows).each(function( index ) { console.log( index + ": " + $(this).text() ); }); 
0
source

You can also use a for loop, which is only for the last three lines:

 var table = document.getElementById('table'), row = table.querySelectorAll('tr'); for(i = 0; i < row.length; i++) { if (i >= 3) { console.log(row[i]); } } 

JSFIDDLE

0
source

Source: https://habr.com/ru/post/1493225/


All Articles