function maxNum(){ var a = $('#num-length'); var maxwidth = 5; if (a.text().length > maxwidth) { a.text(a.text().substring(0, maxwidth)); a.html(a.html() + '...'); } }