Loop through the 1st row of HTML table (GridView) and get the cell content using Javascript The Next CEO of Stack OverflowHow do I loop through or enumerate a JavaScript object?How to loop through a plain JavaScript object with the objects as members?Looping through the content of a file in BashLooping through siblings of a specific row/setting up functionLoop through an array in JavaScriptlooping through gridview using jqueryAccessing the second row in Header in gridviewforeach loop inside two other loops phpLooping Through Gridview with IF ELSE statementHow to loop through GridView rows which have EditItemTemplates

Why is information "lost" when it got into a black hole?

Redefining symbol midway through a document

Do I need to write [sic] when including a quotation with a number less than 10 that isn't written out?

Is a distribution that is normal, but highly skewed, considered Gaussian?

What flight has the highest ratio of timezone difference to flight time?

Is French Guiana a (hard) EU border?

What is the difference between "hamstring tendon" and "common hamstring tendon"?

My ex-girlfriend uses my Apple ID to login to her iPad, do I have to give her my Apple ID password to reset it?

Does the Idaho Potato Commission associate potato skins with healthy eating?

Is it OK to decorate a log book cover?

How to Implement Deterministic Encryption Safely in .NET

free fall ellipse or parabola?

Strange use of "whether ... than ..." in official text

A question about free fall, velocity, and the height of an object.

Physiological effects of huge anime eyes

Expectation in a stochastic differential equation

Can Sneak Attack be used when hitting with an improvised weapon?

What difference does it make using sed with/without whitespaces?

What steps are necessary to read a Modern SSD in Medieval Europe?

Is fine stranded wire ok for main supply line?

What does "shotgun unity" refer to here in this sentence?

Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?

Which one is the true statement?

What was Carter Burke's job for "the company" in Aliens?



Loop through the 1st row of HTML table (GridView) and get the cell content using Javascript



The Next CEO of Stack OverflowHow do I loop through or enumerate a JavaScript object?How to loop through a plain JavaScript object with the objects as members?Looping through the content of a file in BashLooping through siblings of a specific row/setting up functionLoop through an array in JavaScriptlooping through gridview using jqueryAccessing the second row in Header in gridviewforeach loop inside two other loops phpLooping Through Gridview with IF ELSE statementHow to loop through GridView rows which have EditItemTemplates










1















I have a GridView which reads from a file and when I inspect element
its HTML table looks something like this :






<div>
<table>
<tbody>
<tr>
<th id= "header1">...</th>
<th id= "header2">...</th>
<th id= "header3">...</th>
<th id= "header4">...</th>
<th id= "header5">...</th>
<tr>..</tr>
<tr>..</tr>
<tr>..</tr>
<tr>..</tr>
</table>
</div>





I need to loop through the first row to be able to get the header values using javascript. I can't seem to loop through just the first row to extract values.



I understand that I should count the number of columns first to create my "for" loop but I am only able to count my rows.



var table = document.getElementById("table1");
var rowCount = table.rows.length;
for (var r = 0, n = table.rows.length; r < n; r++) {


There's nothing like table.columns.length.How do I do that? Any help would be greatly appreciated.










share|improve this question


























    1















    I have a GridView which reads from a file and when I inspect element
    its HTML table looks something like this :






    <div>
    <table>
    <tbody>
    <tr>
    <th id= "header1">...</th>
    <th id= "header2">...</th>
    <th id= "header3">...</th>
    <th id= "header4">...</th>
    <th id= "header5">...</th>
    <tr>..</tr>
    <tr>..</tr>
    <tr>..</tr>
    <tr>..</tr>
    </table>
    </div>





    I need to loop through the first row to be able to get the header values using javascript. I can't seem to loop through just the first row to extract values.



    I understand that I should count the number of columns first to create my "for" loop but I am only able to count my rows.



    var table = document.getElementById("table1");
    var rowCount = table.rows.length;
    for (var r = 0, n = table.rows.length; r < n; r++) {


    There's nothing like table.columns.length.How do I do that? Any help would be greatly appreciated.










    share|improve this question
























      1












      1








      1








      I have a GridView which reads from a file and when I inspect element
      its HTML table looks something like this :






      <div>
      <table>
      <tbody>
      <tr>
      <th id= "header1">...</th>
      <th id= "header2">...</th>
      <th id= "header3">...</th>
      <th id= "header4">...</th>
      <th id= "header5">...</th>
      <tr>..</tr>
      <tr>..</tr>
      <tr>..</tr>
      <tr>..</tr>
      </table>
      </div>





      I need to loop through the first row to be able to get the header values using javascript. I can't seem to loop through just the first row to extract values.



      I understand that I should count the number of columns first to create my "for" loop but I am only able to count my rows.



      var table = document.getElementById("table1");
      var rowCount = table.rows.length;
      for (var r = 0, n = table.rows.length; r < n; r++) {


      There's nothing like table.columns.length.How do I do that? Any help would be greatly appreciated.










      share|improve this question














      I have a GridView which reads from a file and when I inspect element
      its HTML table looks something like this :






      <div>
      <table>
      <tbody>
      <tr>
      <th id= "header1">...</th>
      <th id= "header2">...</th>
      <th id= "header3">...</th>
      <th id= "header4">...</th>
      <th id= "header5">...</th>
      <tr>..</tr>
      <tr>..</tr>
      <tr>..</tr>
      <tr>..</tr>
      </table>
      </div>





      I need to loop through the first row to be able to get the header values using javascript. I can't seem to loop through just the first row to extract values.



      I understand that I should count the number of columns first to create my "for" loop but I am only able to count my rows.



      var table = document.getElementById("table1");
      var rowCount = table.rows.length;
      for (var r = 0, n = table.rows.length; r < n; r++) {


      There's nothing like table.columns.length.How do I do that? Any help would be greatly appreciated.






      <div>
      <table>
      <tbody>
      <tr>
      <th id= "header1">...</th>
      <th id= "header2">...</th>
      <th id= "header3">...</th>
      <th id= "header4">...</th>
      <th id= "header5">...</th>
      <tr>..</tr>
      <tr>..</tr>
      <tr>..</tr>
      <tr>..</tr>
      </table>
      </div>





      <div>
      <table>
      <tbody>
      <tr>
      <th id= "header1">...</th>
      <th id= "header2">...</th>
      <th id= "header3">...</th>
      <th id= "header4">...</th>
      <th id= "header5">...</th>
      <tr>..</tr>
      <tr>..</tr>
      <tr>..</tr>
      <tr>..</tr>
      </table>
      </div>






      javascript loops gridview html-table rows






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 18:12









      Code.BreakerCode.Breaker

      217




      217






















          1 Answer
          1






          active

          oldest

          votes


















          0














          like that you will get header values in an array






          const el = [...document.querySelectorAll("th")];

          const res = el.map(el => el.innerHTML)

          console.log(res)

          <div>
          <table>
          <tbody>
          <tr>
          <th id="header1">TEXT1</th>
          <th id="header2">TEX2</th>
          <th id="header3">TEXT3</th>
          <th id="header4">TEXT4</th>
          <th id="header5">TEXT5</th>
          </tr>
          <tr>..</tr>
          <tr>..</tr>
          <tr>..</tr>
          <tr>..</tr>
          </table>
          </div>








          share|improve this answer

























          • Thank you. But what about looping? Is it possible to loop through the 1st row in a table like above to get the values?

            – Code.Breaker
            Mar 7 at 19:38











          • what do you mean by the first row ? loop on <tr> ?

            – G.aziz
            Mar 7 at 20:10






          • 1





            yes, loop on the 1st <tr>. I want to be able to visit every <th> within the first <tr> by using a for loop.

            – Code.Breaker
            Mar 7 at 20:25












          • yes and this what i am doing

            – G.aziz
            Mar 7 at 20:36











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050310%2floop-through-the-1st-row-of-html-table-gridview-and-get-the-cell-content-using%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          like that you will get header values in an array






          const el = [...document.querySelectorAll("th")];

          const res = el.map(el => el.innerHTML)

          console.log(res)

          <div>
          <table>
          <tbody>
          <tr>
          <th id="header1">TEXT1</th>
          <th id="header2">TEX2</th>
          <th id="header3">TEXT3</th>
          <th id="header4">TEXT4</th>
          <th id="header5">TEXT5</th>
          </tr>
          <tr>..</tr>
          <tr>..</tr>
          <tr>..</tr>
          <tr>..</tr>
          </table>
          </div>








          share|improve this answer

























          • Thank you. But what about looping? Is it possible to loop through the 1st row in a table like above to get the values?

            – Code.Breaker
            Mar 7 at 19:38











          • what do you mean by the first row ? loop on <tr> ?

            – G.aziz
            Mar 7 at 20:10






          • 1





            yes, loop on the 1st <tr>. I want to be able to visit every <th> within the first <tr> by using a for loop.

            – Code.Breaker
            Mar 7 at 20:25












          • yes and this what i am doing

            – G.aziz
            Mar 7 at 20:36















          0














          like that you will get header values in an array






          const el = [...document.querySelectorAll("th")];

          const res = el.map(el => el.innerHTML)

          console.log(res)

          <div>
          <table>
          <tbody>
          <tr>
          <th id="header1">TEXT1</th>
          <th id="header2">TEX2</th>
          <th id="header3">TEXT3</th>
          <th id="header4">TEXT4</th>
          <th id="header5">TEXT5</th>
          </tr>
          <tr>..</tr>
          <tr>..</tr>
          <tr>..</tr>
          <tr>..</tr>
          </table>
          </div>








          share|improve this answer

























          • Thank you. But what about looping? Is it possible to loop through the 1st row in a table like above to get the values?

            – Code.Breaker
            Mar 7 at 19:38











          • what do you mean by the first row ? loop on <tr> ?

            – G.aziz
            Mar 7 at 20:10






          • 1





            yes, loop on the 1st <tr>. I want to be able to visit every <th> within the first <tr> by using a for loop.

            – Code.Breaker
            Mar 7 at 20:25












          • yes and this what i am doing

            – G.aziz
            Mar 7 at 20:36













          0












          0








          0







          like that you will get header values in an array






          const el = [...document.querySelectorAll("th")];

          const res = el.map(el => el.innerHTML)

          console.log(res)

          <div>
          <table>
          <tbody>
          <tr>
          <th id="header1">TEXT1</th>
          <th id="header2">TEX2</th>
          <th id="header3">TEXT3</th>
          <th id="header4">TEXT4</th>
          <th id="header5">TEXT5</th>
          </tr>
          <tr>..</tr>
          <tr>..</tr>
          <tr>..</tr>
          <tr>..</tr>
          </table>
          </div>








          share|improve this answer















          like that you will get header values in an array






          const el = [...document.querySelectorAll("th")];

          const res = el.map(el => el.innerHTML)

          console.log(res)

          <div>
          <table>
          <tbody>
          <tr>
          <th id="header1">TEXT1</th>
          <th id="header2">TEX2</th>
          <th id="header3">TEXT3</th>
          <th id="header4">TEXT4</th>
          <th id="header5">TEXT5</th>
          </tr>
          <tr>..</tr>
          <tr>..</tr>
          <tr>..</tr>
          <tr>..</tr>
          </table>
          </div>








          const el = [...document.querySelectorAll("th")];

          const res = el.map(el => el.innerHTML)

          console.log(res)

          <div>
          <table>
          <tbody>
          <tr>
          <th id="header1">TEXT1</th>
          <th id="header2">TEX2</th>
          <th id="header3">TEXT3</th>
          <th id="header4">TEXT4</th>
          <th id="header5">TEXT5</th>
          </tr>
          <tr>..</tr>
          <tr>..</tr>
          <tr>..</tr>
          <tr>..</tr>
          </table>
          </div>





          const el = [...document.querySelectorAll("th")];

          const res = el.map(el => el.innerHTML)

          console.log(res)

          <div>
          <table>
          <tbody>
          <tr>
          <th id="header1">TEXT1</th>
          <th id="header2">TEX2</th>
          <th id="header3">TEXT3</th>
          <th id="header4">TEXT4</th>
          <th id="header5">TEXT5</th>
          </tr>
          <tr>..</tr>
          <tr>..</tr>
          <tr>..</tr>
          <tr>..</tr>
          </table>
          </div>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 7 at 20:36

























          answered Mar 7 at 18:18









          G.azizG.aziz

          1,118518




          1,118518












          • Thank you. But what about looping? Is it possible to loop through the 1st row in a table like above to get the values?

            – Code.Breaker
            Mar 7 at 19:38











          • what do you mean by the first row ? loop on <tr> ?

            – G.aziz
            Mar 7 at 20:10






          • 1





            yes, loop on the 1st <tr>. I want to be able to visit every <th> within the first <tr> by using a for loop.

            – Code.Breaker
            Mar 7 at 20:25












          • yes and this what i am doing

            – G.aziz
            Mar 7 at 20:36

















          • Thank you. But what about looping? Is it possible to loop through the 1st row in a table like above to get the values?

            – Code.Breaker
            Mar 7 at 19:38











          • what do you mean by the first row ? loop on <tr> ?

            – G.aziz
            Mar 7 at 20:10






          • 1





            yes, loop on the 1st <tr>. I want to be able to visit every <th> within the first <tr> by using a for loop.

            – Code.Breaker
            Mar 7 at 20:25












          • yes and this what i am doing

            – G.aziz
            Mar 7 at 20:36
















          Thank you. But what about looping? Is it possible to loop through the 1st row in a table like above to get the values?

          – Code.Breaker
          Mar 7 at 19:38





          Thank you. But what about looping? Is it possible to loop through the 1st row in a table like above to get the values?

          – Code.Breaker
          Mar 7 at 19:38













          what do you mean by the first row ? loop on <tr> ?

          – G.aziz
          Mar 7 at 20:10





          what do you mean by the first row ? loop on <tr> ?

          – G.aziz
          Mar 7 at 20:10




          1




          1





          yes, loop on the 1st <tr>. I want to be able to visit every <th> within the first <tr> by using a for loop.

          – Code.Breaker
          Mar 7 at 20:25






          yes, loop on the 1st <tr>. I want to be able to visit every <th> within the first <tr> by using a for loop.

          – Code.Breaker
          Mar 7 at 20:25














          yes and this what i am doing

          – G.aziz
          Mar 7 at 20:36





          yes and this what i am doing

          – G.aziz
          Mar 7 at 20:36



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050310%2floop-through-the-1st-row-of-html-table-gridview-and-get-the-cell-content-using%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

          Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

          Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved