Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6689327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:30:23+00:00 2026-05-26T05:30:23+00:00

Can somebody help me out to troubleshoot this code? I am looking to add

  • 0

Can somebody help me out to troubleshoot this code? I am looking to add all the values of a HTML table column using JQuery. Please see below example I can not get this functional.

The first table is just a normal table holding the data, the second table should be filled dynamically with jQuery adding up the columns.

 <html>
 <head>
 <script type="text/javascript" SRC="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script>
 <script type="text/javascript">  

 //these will hold the totals
 var ages = 0;
 var weights = 0;
 var benchpresses = 0;

 //reference the rows you want to add
 //this will not include the header row
 var rows = $("#data tr:gt(0)");
 rows.children("td:nth-child(2)").each(function() {
 //each time we add the cell to the total
 ages += parseInt($(this).html());
 });
 rows.children("td:nth-child(3)").each(function() {
 weights += parseInt($(this).html());
 });
 rows.children("td:nth-child(4)").each(function() {
 benchpresses += parseInt($(this).html());
 });

 //then output them to the elements
 $("#ages").html(ages);
 $("#weights").html(weights);
 $("#benchpresses").html(benchpresses);

 </script>
 </head>
 <TABLE class=custom id=data>
 <TBODY>
 <TR>
  <TH>name</TH>
  <TH>age</TH>
  <TH>weight</TH>
  <TH>benchpress</TH>
 </TR>
 <TR>
  <TD>stan</TD>
  <TD>27</TD>
  <TD>177</TD>
  <TD>325</TD>
 </TR>
 <TR>
  <TD>rj</TD>
  <TD>30</TD>
  <TD>135</TD>
  <TD>95</TD>
 </TR>
<TR>
  <TD>jose</TD>
  <TD>29</TD>
  <TD>230</TD>
  <TD>375</TD>
</TR>
</TBODY>
</TABLE>
<BR>
<TABLE class=custom>
<TBODY>
<TR>
  <TH>ages</TH>
  <TH>weights</TH>
  <TH>benchpresses</TH>
</TR>
<TR>
  <TD id=ages>&nbsp;</TD>
  <TD id=weights>&nbsp;</TD>
  <TD id=benchpresses>&nbsp;</TD>
</TR>
</TBODY>
</TABLE>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:30:24+00:00Added an answer on May 26, 2026 at 5:30 am

    In your example the code to sum the columns will execute before the columns/tables/data exist. Several ways to fix, easiest is to move the <script> block in your example to after the table definition.

     <html>
     <head>
     <script type="text/javascript" SRC="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script>
    
     </head>
     <TABLE class=custom id=data>
     <TBODY>
     <TR>
      <TH>name</TH>
      <TH>age</TH>
      <TH>weight</TH>
      <TH>benchpress</TH>
     </TR>
     <TR>
      <TD>stan</TD>
      <TD>27</TD>
      <TD>177</TD>
      <TD>325</TD>
     </TR>
     <TR>
      <TD>rj</TD>
      <TD>30</TD>
      <TD>135</TD>
      <TD>95</TD>
     </TR>
    <TR>
      <TD>jose</TD>
      <TD>29</TD>
      <TD>230</TD>
      <TD>375</TD>
    </TR>
    </TBODY>
    </TABLE>
    <BR>
    <TABLE class=custom>
    <TBODY>
    <TR>
      <TH>ages</TH>
      <TH>weights</TH>
      <TH>benchpresses</TH>
    </TR>
    <TR>
      <TD id=ages>&nbsp;</TD>
      <TD id=weights>&nbsp;</TD>
      <TD id=benchpresses>&nbsp;</TD>
    </TR>
    </TBODY>
    </TABLE>
     <script type="text/javascript">  
    
     //these will hold the totals
     var ages = 0;
     var weights = 0;
     var benchpresses = 0;
    
     //reference the rows you want to add
     //this will not include the header row
     var rows = $("#data tr:gt(0)");
     rows.children("td:nth-child(2)").each(function() {
     //each time we add the cell to the total
     ages += parseInt($(this).html());
     });
     rows.children("td:nth-child(3)").each(function() {
     weights += parseInt($(this).html());
     });
     rows.children("td:nth-child(4)").each(function() {
     benchpresses += parseInt($(this).html());
     });
    
     //then output them to the elements
     $("#ages").html(ages);
     $("#weights").html(weights);
     $("#benchpresses").html(benchpresses);
    
     </script>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can somebody help me with this. There is HTML code: <h3> <label> <input type=checkbox
This is a total dah question but I hope somebody can help me out.
I'm trying to optimize this mysql query using EXPLAIN. Can somebody please help me
I am hoping that somebody can help me out with this question. The following
Hopefully somebody can help me out here. I'm working within an embedded ActionScript2 and
hopefully somebody can help The table structure is as follows: tblCompany: compID compName tblOffice:
I hope somebody can help me. I've been trying to write a custom html
Sorry I'm beginner, can somebody help me out? <script> var iW = $(document).width(); $(function()
If I try the getting-started on http://flexmojos.sonatype.org/getting-started.html I get some errors. Can somebody help
Can somebody help me to suggest how can I get the play list from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.