Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Add '0' before single digit numbers jQuery? Reply To: Add '0' before single digit numbers jQuery?

#147330
Kuzyo
Participant

Hi, i made in this way:

$('.box').click(function () {

    $(this).text(function (i, n) {
        var result = Number(n) + 1;
        if ( result < 10 ) {
            return "0" + result;
        } else {
            return result;
        }
    });

});

@Rugg where I can read about this variant of counting :

$(this).text(function (i, n) {

        return Number(n) + 1;

    });

Thanks.