Append Text on Click
HTML
<button>Click</button>
<div id="output"><h1>
</h1></div>
<div id="msg"> </div>
CSS
#output {
font-size: 50px;
}
JavaScript
var count = 0;
$('button').click(function(){
doCount();
writeOutput();
});
function writeOutput() {
var contents = $('#msg').html();
if(count == 1) {
contents = contents + count;
} else {
contents = contents + ',' + count;
}
showText("#msg", contents, 0, 500);
/* $('#output').html(contents) */;
}
function doCount() {
count++;
}
var showText = function (target, message, index, interval) {
if (index < message.length) {
$(target).append(message[index++]);
setTimeout(function () { showText(target, message, index, interval); }, interval);
}
}
/* $(function () {
showText("#msg", "Hello, World!", 0, 500);
}); */