JSFiddle - React, Tailwind, and code Playground

by Seungrae Lee

HTML

<h3>add comma example</h3>
<span id="amount1">186000</span>
<h3>delete comma example</h3>
<span id="amount2">186,000</span>

JavaScript

$.fn.digits = function () {
    return this.each(function () {
        $(this).text($(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
    });
};
$.fn.delcomma = function() {
    return this.each(function() {
       $(this).text($(this).text().replace(/\,/g,'')); 
    });
}

$(function () {
    $("#amount1").digits();
    $("#amount2").delcomma();
}); //onload