jQuery - comma on number function

0 votes
223 views
added Jun 1, 2018 in jQuery by LC Marshal Captain (25,790 points)
edited Aug 29, 2018 by LC Marshal
//placed plugin globally, so it can be used globally 
$.fn.digits = function(){ 
    return this.each(function(){ 
        $(this).text( $(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") ); 
    })
}

//to add comma on JSON object 
var areaname = $('h1.page-header').text(),
    lookforstate = $('ol.breadcrumb li:last-child').text(),
    trimstate = lookforstate.split(","),
    resultstate  = trimstate [trimstate.length-1],
    getstate = $.trim(resultstate),
    outlookLislnk = 'https://alice.propedge.my/property/v1/nsearch?&state=',
    incDistrcRent = '&listing_type=rental&district=',
    fulloutLisRent = outlookLislnk + getstate + incDistrcRent + areaname;

$('input#count-rent').fadeIn(300).val(fulloutLisRent.found).digits();
$('.count-rent').fadeIn(300);
});
lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...