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 6963309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:46:23+00:00 2026-05-27T15:46:23+00:00

the HTML below <div class=commentlinks> <a class=commentlinked blogcount>3</a> <a class=commentlinked fbcount>2</a> <a class=commentlinked disqcount>1</a>

  • 0

the HTML below

<div class="commentlinks">
    <a class="commentlinked blogcount">3</a>
    <a class="commentlinked fbcount">2</a>
    <a class="commentlinked disqcount">1</a>
    <a class="allcommentcount"></a>
</div>

with this jQuery

$('.commentlinks').each(function() {
var currentValue = parseInt($(".blogcount").text());
var currentValue2 = parseInt($(".fbcount").text());
var currentValue3 = parseInt($(".disqcount").text());
var newValue = currentValue + currentValue2 + currentValue3;
$(".allcommentcount").text(newValue);
});

Returns this successfully http://jsfiddle.net/hQzZQ/22/

3
2
1
6

but when i have this html

<div class="commentlinks">
    <a class="commentlinked blogcount">3</a>
    <a class="commentlinked fbcount">2</a>
    <a class="commentlinked disqcount">1</a>
    <a class="allcommentcount"></a>
</div>

<div class="commentlinks">
    <a class="commentlinked blogcount">7</a>
    <a class="commentlinked fbcount">6</a>
    <a class="commentlinked disqcount">1</a>
    <a class="allcommentcount"></a>
</div>

It Returns http://jsfiddle.net/hQzZQ/23/

3 2 1 74
7 6 1 74

why is it returning it incorrectly help me fix it please!

  • 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-27T15:46:23+00:00Added an answer on May 27, 2026 at 3:46 pm

    You have to use find or children to select the elements in the current context. Also, use parseInt(.., 10) to parse numbers.

    Demo: http://jsfiddle.net/sym7H/

    $('.commentlinks').each(function() {
        var $this = $(this);
        var currentValue = parseInt($this.find(".blogcount").text(), 10);
        var currentValue2 = parseInt($this.find(".fbcount").text(), 10);
        var currentValue3 = parseInt($this.find(".disqcount").text(), 10);
        var newValue = currentValue + currentValue2 + currentValue3;
        $this.find(".allcommentcount").text(newValue);
    });
    

    If your document is well-structured, you can also use .children("a") to find the elements, then use .eq(..) or .slice(.., 1) to select the elements. This has an improved efficiency.

    Demo: http://jsfiddle.net/sym7H/1/

    $('.commentlinks').each(function() {
        var $anchors = $(this).children("a"),
            currentValue = parseInt($anchors.eq(0).text(), 10),
            currentValue2 = parseInt($anchors.eq(1).text(), 10),
            currentValue3 = parseInt($anchors.eq(2).text(), 10),
            newValue = currentValue + currentValue2 + currentValue3;
        $anchors.eq(3).text(newValue);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please check my HTML below: <table cellpadding=0 cellpadding=0 border=0> <tr> <td> <div class=toogler>Demo1</div> </td>
I have a HTML document with the below setup: <div class=main-div style=padding: 5px; border:
The code is as below: <html> <head> <title>test</title> </head> <body> <div><span>shanghai</span><span class=margin> </span><span>male</span></div> </body>
i wonder if below, generating content the jQuery 1.4 way $(<div />, { class:
I have a HTML document like below: <td> <div class="commentLink"> <a href="javascript:ShowBox()">Show</a> </div> <div
My problem is with the below html <div class=editor-container> <div class=editor-row curFocus> <div class=editor-label>
The divs below appear in that order in the HTML I am parsing. //div[contains(@class,'top-container')]//font/text()
I have got below JQuery where I am performing the .load function. $(.load-fragment).each(function() {
Given the HTML below, I am trying to use jQuery to match all the
In the HTML below, the layout works when the actionBar class has a float

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.