1

I have a HTML table

 <table id="mytab">
  <thead>
    <th>col1</th>
    <th>col2</th>
  </thead>
  <tbody>
  <tr>
    <td>1</td>
    <td>2</td>
  </tr>
  <tr>
     <td>11</td>
     <td>22</td>
  </tbody>
 </table>

and i am writing the jquery function

  function LoopTable()
  {
      $row = $('#mytab tbody >tr"); //here I have successfully find all the rows.

     //now i want to loop on rows and find each column row
     for (var i=0; i<$rows.length; i++)
     {
         //need something here to find col data

     }

what I should use to have column values from row

5
  • dump the $row value , you may get clue Commented Jun 30, 2013 at 10:18
  • Meaning: try console.dir($row) in your browsers dev console (press f12 in IE/Chrome to open it) Commented Jun 30, 2013 at 10:21
  • And you don't want to use each() method? You need each td value, or? Commented Jun 30, 2013 at 10:21
  • because I want to work with only some columns and rows thats why I don't want to use each() method, I want somthing $rows[i].cells[0].val() Commented Jun 30, 2013 at 10:25
  • a lot of mistakes are in OP code. such as ' closing with " and $row is initialize and $rows is used in for loop Commented Jun 30, 2013 at 10:27

2 Answers 2

3

Updated code

$(document).ready(function() {
    var rows = $('#mytab tbody >tr');
    var columns;
    for (var i = 0; i < rows.length; i++) {
        columns = $(rows[i]).find('td');
        for (var j = 0; j < columns.length; j++) {
            console.log($(columns[j]).html());
        }
    }
});
Sign up to request clarification or add additional context in comments.

Comments

0
for (var i=0; i<$rows.length; i++)
{
    $.each($row[i].children("td"), function(key, value) {
         console.log(value);
    });
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.