how to repeat for loop RRS feed

  • Question

  • User-1634604574 posted

    i have this table i want to read this table row by for loop when loop completed read all rows of table remove first row then when repeate loop read the table row from 

    the first column after completed then remove first row an so on when table row are except th are zero then stop for loop how can i do it?

    (Note: my table row are dynamic it mean row of rows are dynamic not static loop depending on length of table)

    <table id="tb">









    Saturday, March 9, 2019 7:26 AM

All replies

  • User475983607 posted

    Your requirement does not make logical sense.   When asking questions on the forum, always share the code that you wrote to solve the problem.  Explain the expected results and the actual results.  This helps us to help you because this process highlights holes in your understanding.  Then we can fill those holes with knowledge.  When you do not post code it looks like you are not trying.  

    The code sample below uses a button click to traverse table rows from top to bottom.   Feel free to update the code to suite your needs.

    <!DOCTYPE html>
        <meta name="viewport" content="width=device-width" />
            .selected {
            <form id="List_Form">
                        <tr class="selected">
                <input id="Next" type="button" value="Next" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
            $('#Next').click(function () {
                var row = $('.selected');
                var nextRow = $(row).next('tr').addClass('selected');
                if (!$(nextRow).is('tr')) {
                    $('#List_Form > table > tbody > tr:nth-child(1)').addClass('selected');

    Saturday, March 9, 2019 1:12 PM
  • User-2054057000 posted

    Are you trying to read value by looping through all tr elements ?

    If yes then you can do it through jQuery Each method quite easily. The code looks something like this:

    $("table tr").each(function (index, value) { 
      console.log(value); // gives the trs value one by one

    Now If you want to read all tds value then you extend the above code:

    $("table tr").each(function (index, value) { 
      $(value).find("td").each(function (index, value) { 
        console.log(value); // gives the tds value one by one 


    Sunday, March 10, 2019 3:51 PM