$(function () { var $character = $('.character'), count = 0; setInterval(function () { var hexcode = '0000' + (count++).toString(16); hexcode = '&#x' + hexcode.substr(hexcode.length - 4) + ';'; $character.html(hexcode); }, 100); });