JSFiddle - React, Tailwind, and code Playground
by Emmanuel Garcia
HTML
<div class="price">25000</div>
CSS
.enMoney::before {
content:"$";
}
.negMoney {
color:red;
}
div.negMoney::before {
content:'($';
}
div.negMoney::after {
content:')';
}
JavaScript
$('* .price').each(function () {
var item = $(this).text();
var num = Number(item).toLocaleString('en');
if (Number(item) < 0) {
num = num.replace('-','');
$(this).addClass('negMoney');
}else{
$(this).addClass('enMoney');
}
$(this).text(num);
});