Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
Can i add a comma (,) dynamically to a CSS pseudo element which its value is coming from CSS variable

I want to insert the commas appropriately between the numbers. eg: 6,350

is there any way I can achieve this in the following scenario

setTimeout(function () {
  $('.number-counter').each(function () {
    $(this).addClass('inView');
  });
}, 500);
@property --num {
  syntax: "<integer>";
  initial-value: 0;
  inherits: false;
}

.number-counter {
  transition: --num 3s;
  counter-set: num var(--num);
  font: 800 40px system-ui;
}
.number-counter::after {
  content: counter(num);
}
.number-counter.inView {
  --num: var(--count);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="number-counter" style="--count: 6350;"></div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I have tried to add this code in CSS but there is no way to count the digits in CSS so I have added the comma(,) using jQuery. I hope this will help you. It will add the comma after 3 digit.

setTimeout(function () {
  jQuery('.number-counter').each(function () {
    jQuery(this).addClass('inView');
    var $this = jQuery(this);
     countTo = $this.attr('data-count');
  jQuery({ countNum: $this.text()}).animate({countNum: countTo},
    {     
      easing: 'linear',
      step: function() {
              $this.text(commaSeparateNumber(Math.ceil(this.countNum)));
  },
  complete: function() {
    $this.text(commaSeparateNumber(Math.ceil(this.countNum)));
      }
    });
  });
}, 500);
function commaSeparateNumber(val) {
  while (/(\d+)(\d{3})/.test(val.toString())) {
    val = val.toString().replace(/(\d+)(\d{3})/, '$1' + ',' + '$2');
  }
  return val;
}
@property --num {
  syntax: "<integer>";
  initial-value: 0;
  inherits: false;
}

.number-counter {
  transition: --num 3s;
  counter-set: num var(--num);
  font: 800 40px system-ui;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="number-counter" style="--count: 6350;" data-count="6350"></div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!