How to Add Commas to Dynamic Numbers

In this Elementor tutorial I will show you how to add commas automatically to larger numbers. This is really helpful if you are displaying large dynamic data and need to display it correctly on the front end.

CodePen:
https://codepen.io/engza/pen/jOyOYK

Timestamps:

  • 0:00 Introduction
  • 0:50 Elementor Tutorial Begins

JavaScript Code:

				
					<script>
jQuery(function($){
   function numberWithCommas(number) {
    var parts = number.toString().split(".");
    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    return parts.join(".");
}
  $(document).ready(function() {
  $("#wicky h2,#wickydesign h2").each(function() {
    var num = $(this).text();
    var commaNum = numberWithCommas(num);
    $(this).text(commaNum);
  });
});
});
</script>
				
			

Free Brand Messaging Worksheet

Define Your Voice and Connect with Your Audience

More Free Resources

Let's Work Together

Big ideas start with a quick chat. Let’s talk!