JS Comma Thousand Separator for Counter?How to print a number with commas as thousands separators in JavaScriptEasy way to turn JavaScript array into comma-separated list?How to convert a comma separated string to an array?How to print a number with commas as thousands separators in JavaScriptJavascript Limit CommasCreating a regex to parse html to MXML syntaxLife Counter Issuespan count up with a condition javascriptHow to replace text based on counter value?jQuery - Each counting resetting issueFirebase Realtime Database and Cloud Functions — increment counter based on data nodes

What is the meaning of "it" in "as luck would have it"?

English idiomatic equivalents of 能骗就骗 (if you can cheat, then cheat)

Why is my 401k manager recommending me to save more?

Does friction always oppose motion?

Does "boire un jus" tend to mean "coffee" or "juice of fruit"?

My mom helped me cosign a car and now she wants to take it

Is this house-rule removing the increased effect of cantrips at higher character levels balanced?

Robots in a spaceship

How can this fractal shape perfectly cover a certain platonic solid?

Why should I allow multiple IP addresses on a website for a single session?

What happens if a caster is surprised while casting a spell with a long casting time?

Avoiding repetition when using the "snprintf idiom" to write text

What's the lunar calendar of two moons

What verb goes with "coup"?

Does a lens with a bigger max. aperture focus faster than a lens with a smaller max. aperture?

What was the first science fiction or fantasy multiple choice book?

Is SpaceX propulsively deorbiting a Starlink satellite already?

What are the children of two Muggle-borns called?

Why doesn't this nested command substitution of "ps" produce the expected output?

Have any large aeroplanes been landed — safely and without damage — in locations that they could not be flown away from?

What is my external HDD doing?

Tricolour nonogram

Why doesn't SpaceX land boosters in Africa?

Installed software from source, how to say yum not to install it from package?



JS Comma Thousand Separator for Counter?


How to print a number with commas as thousands separators in JavaScriptEasy way to turn JavaScript array into comma-separated list?How to convert a comma separated string to an array?How to print a number with commas as thousands separators in JavaScriptJavascript Limit CommasCreating a regex to parse html to MXML syntaxLife Counter Issuespan count up with a condition javascriptHow to replace text based on counter value?jQuery - Each counting resetting issueFirebase Realtime Database and Cloud Functions — increment counter based on data nodes













0















I have a working number counter section on a site I'm working on and I don't know much JS, I have some code that works but it breaks the front-end and stops the counter. I'm hoping someone can help me understand how to put the pieces I have together correctly.



I've tried both the functions separately and together, probably incorrectly. The second function which deals with the thousand comma works, however it kicks out the front end and the counting function.



I'm not sure what happened with the #shiva element, but I've replaced this overall with #counter as the function works across the board rather than one div element only. I've left both in just now in case theres another way.



HTML:



<div id="counter">
<div class="row">
<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">1688019</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">82150</span></div>
<h2>Text</h2>
</div>
</div>

<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">10505</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">168260</span></div>
<h2>Text</h2>
</div>

</div>
</div>
</div>


Counter:



$('.count').each(function () 
$(this).prop('Counter', 0).animate(
Counter: $(this).text()
,
duration: 2000,
easing: 'swing',
step: function (now)
$(this).text(Math.ceil(now));

);
);


Separator:



 function numberWithCommas(number) 
var parts = number.toString().split('.');
parts[0] = parts[0].replace(/B(?=(d3)+(?!d))/g, ',');
return parts.join('.');


$('#counter').each(function ()
var num = $(this).text();
var commaNum = numberWithCommas(num);
$(this).text(commaNum);
);









share|improve this question

















  • 1





    1st of all Keep id's (#) specfic to single elements, use class attribute syntax for multi-elements

    – Francis Leigh
    Mar 25 at 16:29











  • I had that before Francis, but the formatter would only work on the first div element and not across all four.

    – Caitlin Mooney
    Mar 25 at 16:30















0















I have a working number counter section on a site I'm working on and I don't know much JS, I have some code that works but it breaks the front-end and stops the counter. I'm hoping someone can help me understand how to put the pieces I have together correctly.



I've tried both the functions separately and together, probably incorrectly. The second function which deals with the thousand comma works, however it kicks out the front end and the counting function.



I'm not sure what happened with the #shiva element, but I've replaced this overall with #counter as the function works across the board rather than one div element only. I've left both in just now in case theres another way.



HTML:



<div id="counter">
<div class="row">
<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">1688019</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">82150</span></div>
<h2>Text</h2>
</div>
</div>

<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">10505</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">168260</span></div>
<h2>Text</h2>
</div>

</div>
</div>
</div>


Counter:



$('.count').each(function () 
$(this).prop('Counter', 0).animate(
Counter: $(this).text()
,
duration: 2000,
easing: 'swing',
step: function (now)
$(this).text(Math.ceil(now));

);
);


Separator:



 function numberWithCommas(number) 
var parts = number.toString().split('.');
parts[0] = parts[0].replace(/B(?=(d3)+(?!d))/g, ',');
return parts.join('.');


$('#counter').each(function ()
var num = $(this).text();
var commaNum = numberWithCommas(num);
$(this).text(commaNum);
);









share|improve this question

















  • 1





    1st of all Keep id's (#) specfic to single elements, use class attribute syntax for multi-elements

    – Francis Leigh
    Mar 25 at 16:29











  • I had that before Francis, but the formatter would only work on the first div element and not across all four.

    – Caitlin Mooney
    Mar 25 at 16:30













0












0








0








I have a working number counter section on a site I'm working on and I don't know much JS, I have some code that works but it breaks the front-end and stops the counter. I'm hoping someone can help me understand how to put the pieces I have together correctly.



I've tried both the functions separately and together, probably incorrectly. The second function which deals with the thousand comma works, however it kicks out the front end and the counting function.



I'm not sure what happened with the #shiva element, but I've replaced this overall with #counter as the function works across the board rather than one div element only. I've left both in just now in case theres another way.



HTML:



<div id="counter">
<div class="row">
<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">1688019</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">82150</span></div>
<h2>Text</h2>
</div>
</div>

<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">10505</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">168260</span></div>
<h2>Text</h2>
</div>

</div>
</div>
</div>


Counter:



$('.count').each(function () 
$(this).prop('Counter', 0).animate(
Counter: $(this).text()
,
duration: 2000,
easing: 'swing',
step: function (now)
$(this).text(Math.ceil(now));

);
);


Separator:



 function numberWithCommas(number) 
var parts = number.toString().split('.');
parts[0] = parts[0].replace(/B(?=(d3)+(?!d))/g, ',');
return parts.join('.');


$('#counter').each(function ()
var num = $(this).text();
var commaNum = numberWithCommas(num);
$(this).text(commaNum);
);









share|improve this question














I have a working number counter section on a site I'm working on and I don't know much JS, I have some code that works but it breaks the front-end and stops the counter. I'm hoping someone can help me understand how to put the pieces I have together correctly.



I've tried both the functions separately and together, probably incorrectly. The second function which deals with the thousand comma works, however it kicks out the front end and the counting function.



I'm not sure what happened with the #shiva element, but I've replaced this overall with #counter as the function works across the board rather than one div element only. I've left both in just now in case theres another way.



HTML:



<div id="counter">
<div class="row">
<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">1688019</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">82150</span></div>
<h2>Text</h2>
</div>
</div>

<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">10505</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">168260</span></div>
<h2>Text</h2>
</div>

</div>
</div>
</div>


Counter:



$('.count').each(function () 
$(this).prop('Counter', 0).animate(
Counter: $(this).text()
,
duration: 2000,
easing: 'swing',
step: function (now)
$(this).text(Math.ceil(now));

);
);


Separator:



 function numberWithCommas(number) 
var parts = number.toString().split('.');
parts[0] = parts[0].replace(/B(?=(d3)+(?!d))/g, ',');
return parts.join('.');


$('#counter').each(function ()
var num = $(this).text();
var commaNum = numberWithCommas(num);
$(this).text(commaNum);
);






javascript






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 16:26









Caitlin MooneyCaitlin Mooney

669 bronze badges




669 bronze badges







  • 1





    1st of all Keep id's (#) specfic to single elements, use class attribute syntax for multi-elements

    – Francis Leigh
    Mar 25 at 16:29











  • I had that before Francis, but the formatter would only work on the first div element and not across all four.

    – Caitlin Mooney
    Mar 25 at 16:30












  • 1





    1st of all Keep id's (#) specfic to single elements, use class attribute syntax for multi-elements

    – Francis Leigh
    Mar 25 at 16:29











  • I had that before Francis, but the formatter would only work on the first div element and not across all four.

    – Caitlin Mooney
    Mar 25 at 16:30







1




1





1st of all Keep id's (#) specfic to single elements, use class attribute syntax for multi-elements

– Francis Leigh
Mar 25 at 16:29





1st of all Keep id's (#) specfic to single elements, use class attribute syntax for multi-elements

– Francis Leigh
Mar 25 at 16:29













I had that before Francis, but the formatter would only work on the first div element and not across all four.

– Caitlin Mooney
Mar 25 at 16:30





I had that before Francis, but the formatter would only work on the first div element and not across all four.

– Caitlin Mooney
Mar 25 at 16:30










1 Answer
1






active

oldest

votes


















1














Someone answered using a similar example to comma by thousands, you just had to adapt it for your situation. Read here How to print a number with commas as thousands separators in JavaScript



The counter you need to replace it after it animates,



 $('.count').each(function () 
$(this).prop('Counter', 0).animate(
Counter: $(this).text()
,
duration: 2000,
easing: 'swing',
step: function (now)
$(this).text(Math.ceil(now));
$(this).text(convert($(this).text()))

);
);


Steps:



  • Loop through each .count element

  • Replace each .count number by our functions return result

  • Our function uses regexp to format the string, combining and joining

  • Set the value in .count to our new result


Example







 

const convert = str => $))/;
// Set a variable
let currStr;
// Start loop
do str.split(`.`)[0])
.replace(regx, `$1,$2`)
while (currStr.match(regx)); // Loop

// Return our result from function
return (str.split(`.`)[1]) ?
currStr.concat(`.`, str.split(`.`)[1]) :
currStr;
;


function total()
let total = 0;
$('.count').each(function()
let v = parseInt($(this).text());
total = v + total
)
return total;


$('.count').each(function ()
$(this).prop('Counter', 0).animate(
Counter: $(this).text()
,
duration: 2000,
easing: 'swing',
step: function (now)
$(this).text(Math.ceil(now));
$(this).text(convert($(this).text()))

);
);

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="counter">
<div class="row">
<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">1688019</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">82150</span></div>
<h2>Text</h2>
</div>
</div>

<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">10505</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">168260</span></div>
<h2>Text</h2>
</div>

</div>
</div>
</div>








share|improve this answer

























  • This works well but the counting function does not work now.

    – Caitlin Mooney
    Mar 25 at 16:39











  • @CaitlinMooney this isn't meant to be added to your code. This is to substitute your code. It is the complete script and HTML. You put the Javascript in the <script> tag </script> and the html in your body.

    – Raymond
    Mar 25 at 16:41












  • I see what you want, you wanted a counter too.

    – Raymond
    Mar 25 at 16:43











  • Yes this is what I did, now the counter does not count but is static. I previously had a counter which animates from 0 to given number.

    – Caitlin Mooney
    Mar 25 at 16:43











  • Doesnt seem to be working for me, not entirely sure why..

    – Caitlin Mooney
    Mar 25 at 16:53










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%2f55342332%2fjs-comma-thousand-separator-for-counter%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









1














Someone answered using a similar example to comma by thousands, you just had to adapt it for your situation. Read here How to print a number with commas as thousands separators in JavaScript



The counter you need to replace it after it animates,



 $('.count').each(function () 
$(this).prop('Counter', 0).animate(
Counter: $(this).text()
,
duration: 2000,
easing: 'swing',
step: function (now)
$(this).text(Math.ceil(now));
$(this).text(convert($(this).text()))

);
);


Steps:



  • Loop through each .count element

  • Replace each .count number by our functions return result

  • Our function uses regexp to format the string, combining and joining

  • Set the value in .count to our new result


Example







 

const convert = str => $))/;
// Set a variable
let currStr;
// Start loop
do str.split(`.`)[0])
.replace(regx, `$1,$2`)
while (currStr.match(regx)); // Loop

// Return our result from function
return (str.split(`.`)[1]) ?
currStr.concat(`.`, str.split(`.`)[1]) :
currStr;
;


function total()
let total = 0;
$('.count').each(function()
let v = parseInt($(this).text());
total = v + total
)
return total;


$('.count').each(function ()
$(this).prop('Counter', 0).animate(
Counter: $(this).text()
,
duration: 2000,
easing: 'swing',
step: function (now)
$(this).text(Math.ceil(now));
$(this).text(convert($(this).text()))

);
);

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="counter">
<div class="row">
<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">1688019</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">82150</span></div>
<h2>Text</h2>
</div>
</div>

<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">10505</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">168260</span></div>
<h2>Text</h2>
</div>

</div>
</div>
</div>








share|improve this answer

























  • This works well but the counting function does not work now.

    – Caitlin Mooney
    Mar 25 at 16:39











  • @CaitlinMooney this isn't meant to be added to your code. This is to substitute your code. It is the complete script and HTML. You put the Javascript in the <script> tag </script> and the html in your body.

    – Raymond
    Mar 25 at 16:41












  • I see what you want, you wanted a counter too.

    – Raymond
    Mar 25 at 16:43











  • Yes this is what I did, now the counter does not count but is static. I previously had a counter which animates from 0 to given number.

    – Caitlin Mooney
    Mar 25 at 16:43











  • Doesnt seem to be working for me, not entirely sure why..

    – Caitlin Mooney
    Mar 25 at 16:53















1














Someone answered using a similar example to comma by thousands, you just had to adapt it for your situation. Read here How to print a number with commas as thousands separators in JavaScript



The counter you need to replace it after it animates,



 $('.count').each(function () 
$(this).prop('Counter', 0).animate(
Counter: $(this).text()
,
duration: 2000,
easing: 'swing',
step: function (now)
$(this).text(Math.ceil(now));
$(this).text(convert($(this).text()))

);
);


Steps:



  • Loop through each .count element

  • Replace each .count number by our functions return result

  • Our function uses regexp to format the string, combining and joining

  • Set the value in .count to our new result


Example







 

const convert = str => $))/;
// Set a variable
let currStr;
// Start loop
do str.split(`.`)[0])
.replace(regx, `$1,$2`)
while (currStr.match(regx)); // Loop

// Return our result from function
return (str.split(`.`)[1]) ?
currStr.concat(`.`, str.split(`.`)[1]) :
currStr;
;


function total()
let total = 0;
$('.count').each(function()
let v = parseInt($(this).text());
total = v + total
)
return total;


$('.count').each(function ()
$(this).prop('Counter', 0).animate(
Counter: $(this).text()
,
duration: 2000,
easing: 'swing',
step: function (now)
$(this).text(Math.ceil(now));
$(this).text(convert($(this).text()))

);
);

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="counter">
<div class="row">
<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">1688019</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">82150</span></div>
<h2>Text</h2>
</div>
</div>

<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">10505</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">168260</span></div>
<h2>Text</h2>
</div>

</div>
</div>
</div>








share|improve this answer

























  • This works well but the counting function does not work now.

    – Caitlin Mooney
    Mar 25 at 16:39











  • @CaitlinMooney this isn't meant to be added to your code. This is to substitute your code. It is the complete script and HTML. You put the Javascript in the <script> tag </script> and the html in your body.

    – Raymond
    Mar 25 at 16:41












  • I see what you want, you wanted a counter too.

    – Raymond
    Mar 25 at 16:43











  • Yes this is what I did, now the counter does not count but is static. I previously had a counter which animates from 0 to given number.

    – Caitlin Mooney
    Mar 25 at 16:43











  • Doesnt seem to be working for me, not entirely sure why..

    – Caitlin Mooney
    Mar 25 at 16:53













1












1








1







Someone answered using a similar example to comma by thousands, you just had to adapt it for your situation. Read here How to print a number with commas as thousands separators in JavaScript



The counter you need to replace it after it animates,



 $('.count').each(function () 
$(this).prop('Counter', 0).animate(
Counter: $(this).text()
,
duration: 2000,
easing: 'swing',
step: function (now)
$(this).text(Math.ceil(now));
$(this).text(convert($(this).text()))

);
);


Steps:



  • Loop through each .count element

  • Replace each .count number by our functions return result

  • Our function uses regexp to format the string, combining and joining

  • Set the value in .count to our new result


Example







 

const convert = str => $))/;
// Set a variable
let currStr;
// Start loop
do str.split(`.`)[0])
.replace(regx, `$1,$2`)
while (currStr.match(regx)); // Loop

// Return our result from function
return (str.split(`.`)[1]) ?
currStr.concat(`.`, str.split(`.`)[1]) :
currStr;
;


function total()
let total = 0;
$('.count').each(function()
let v = parseInt($(this).text());
total = v + total
)
return total;


$('.count').each(function ()
$(this).prop('Counter', 0).animate(
Counter: $(this).text()
,
duration: 2000,
easing: 'swing',
step: function (now)
$(this).text(Math.ceil(now));
$(this).text(convert($(this).text()))

);
);

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="counter">
<div class="row">
<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">1688019</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">82150</span></div>
<h2>Text</h2>
</div>
</div>

<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">10505</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">168260</span></div>
<h2>Text</h2>
</div>

</div>
</div>
</div>








share|improve this answer















Someone answered using a similar example to comma by thousands, you just had to adapt it for your situation. Read here How to print a number with commas as thousands separators in JavaScript



The counter you need to replace it after it animates,



 $('.count').each(function () 
$(this).prop('Counter', 0).animate(
Counter: $(this).text()
,
duration: 2000,
easing: 'swing',
step: function (now)
$(this).text(Math.ceil(now));
$(this).text(convert($(this).text()))

);
);


Steps:



  • Loop through each .count element

  • Replace each .count number by our functions return result

  • Our function uses regexp to format the string, combining and joining

  • Set the value in .count to our new result


Example







 

const convert = str => $))/;
// Set a variable
let currStr;
// Start loop
do str.split(`.`)[0])
.replace(regx, `$1,$2`)
while (currStr.match(regx)); // Loop

// Return our result from function
return (str.split(`.`)[1]) ?
currStr.concat(`.`, str.split(`.`)[1]) :
currStr;
;


function total()
let total = 0;
$('.count').each(function()
let v = parseInt($(this).text());
total = v + total
)
return total;


$('.count').each(function ()
$(this).prop('Counter', 0).animate(
Counter: $(this).text()
,
duration: 2000,
easing: 'swing',
step: function (now)
$(this).text(Math.ceil(now));
$(this).text(convert($(this).text()))

);
);

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="counter">
<div class="row">
<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">1688019</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">82150</span></div>
<h2>Text</h2>
</div>
</div>

<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">10505</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">168260</span></div>
<h2>Text</h2>
</div>

</div>
</div>
</div>








 

const convert = str => $))/;
// Set a variable
let currStr;
// Start loop
do str.split(`.`)[0])
.replace(regx, `$1,$2`)
while (currStr.match(regx)); // Loop

// Return our result from function
return (str.split(`.`)[1]) ?
currStr.concat(`.`, str.split(`.`)[1]) :
currStr;
;


function total()
let total = 0;
$('.count').each(function()
let v = parseInt($(this).text());
total = v + total
)
return total;


$('.count').each(function ()
$(this).prop('Counter', 0).animate(
Counter: $(this).text()
,
duration: 2000,
easing: 'swing',
step: function (now)
$(this).text(Math.ceil(now));
$(this).text(convert($(this).text()))

);
);

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="counter">
<div class="row">
<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">1688019</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">82150</span></div>
<h2>Text</h2>
</div>
</div>

<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">10505</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">168260</span></div>
<h2>Text</h2>
</div>

</div>
</div>
</div>





 

const convert = str => $))/;
// Set a variable
let currStr;
// Start loop
do str.split(`.`)[0])
.replace(regx, `$1,$2`)
while (currStr.match(regx)); // Loop

// Return our result from function
return (str.split(`.`)[1]) ?
currStr.concat(`.`, str.split(`.`)[1]) :
currStr;
;


function total()
let total = 0;
$('.count').each(function()
let v = parseInt($(this).text());
total = v + total
)
return total;


$('.count').each(function ()
$(this).prop('Counter', 0).animate(
Counter: $(this).text()
,
duration: 2000,
easing: 'swing',
step: function (now)
$(this).text(Math.ceil(now));
$(this).text(convert($(this).text()))

);
);

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="counter">
<div class="row">
<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">1688019</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">82150</span></div>
<h2>Text</h2>
</div>
</div>

<div class="col span-1-of-2">
<div class="row">
<div id="shiva"><span class="count">10505</span></div>
<h2>Text</h2>
</div>

<div class="row">
<div id="shiva"><span class="count">168260</span></div>
<h2>Text</h2>
</div>

</div>
</div>
</div>






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 25 at 17:12

























answered Mar 25 at 16:36









RaymondRaymond

1,1454 silver badges16 bronze badges




1,1454 silver badges16 bronze badges












  • This works well but the counting function does not work now.

    – Caitlin Mooney
    Mar 25 at 16:39











  • @CaitlinMooney this isn't meant to be added to your code. This is to substitute your code. It is the complete script and HTML. You put the Javascript in the <script> tag </script> and the html in your body.

    – Raymond
    Mar 25 at 16:41












  • I see what you want, you wanted a counter too.

    – Raymond
    Mar 25 at 16:43











  • Yes this is what I did, now the counter does not count but is static. I previously had a counter which animates from 0 to given number.

    – Caitlin Mooney
    Mar 25 at 16:43











  • Doesnt seem to be working for me, not entirely sure why..

    – Caitlin Mooney
    Mar 25 at 16:53

















  • This works well but the counting function does not work now.

    – Caitlin Mooney
    Mar 25 at 16:39











  • @CaitlinMooney this isn't meant to be added to your code. This is to substitute your code. It is the complete script and HTML. You put the Javascript in the <script> tag </script> and the html in your body.

    – Raymond
    Mar 25 at 16:41












  • I see what you want, you wanted a counter too.

    – Raymond
    Mar 25 at 16:43











  • Yes this is what I did, now the counter does not count but is static. I previously had a counter which animates from 0 to given number.

    – Caitlin Mooney
    Mar 25 at 16:43











  • Doesnt seem to be working for me, not entirely sure why..

    – Caitlin Mooney
    Mar 25 at 16:53
















This works well but the counting function does not work now.

– Caitlin Mooney
Mar 25 at 16:39





This works well but the counting function does not work now.

– Caitlin Mooney
Mar 25 at 16:39













@CaitlinMooney this isn't meant to be added to your code. This is to substitute your code. It is the complete script and HTML. You put the Javascript in the <script> tag </script> and the html in your body.

– Raymond
Mar 25 at 16:41






@CaitlinMooney this isn't meant to be added to your code. This is to substitute your code. It is the complete script and HTML. You put the Javascript in the <script> tag </script> and the html in your body.

– Raymond
Mar 25 at 16:41














I see what you want, you wanted a counter too.

– Raymond
Mar 25 at 16:43





I see what you want, you wanted a counter too.

– Raymond
Mar 25 at 16:43













Yes this is what I did, now the counter does not count but is static. I previously had a counter which animates from 0 to given number.

– Caitlin Mooney
Mar 25 at 16:43





Yes this is what I did, now the counter does not count but is static. I previously had a counter which animates from 0 to given number.

– Caitlin Mooney
Mar 25 at 16:43













Doesnt seem to be working for me, not entirely sure why..

– Caitlin Mooney
Mar 25 at 16:53





Doesnt seem to be working for me, not entirely sure why..

– Caitlin Mooney
Mar 25 at 16:53






Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















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%2f55342332%2fjs-comma-thousand-separator-for-counter%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

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해