Counter

by cliftonyeo

HTML

<button>Click</button>
<div id="output">___</div>

CSS

#output {
    font-size:50px;
}

JavaScript

var count = 0;

$('button').click(function(){
    
    doCount();
    writeOutput();
    
});


function writeOutput() {
    var contents = $('#output').html();    
       //selects #output, and gets the html content out of it
    
    if(count == 1) {
        contents = contents + count;
    } else {
        contents = count + ',' + contents + ',' + count;
    }
    
    $('#output').html(contents);
}


function doCount () {
    
    count++;
}