Treating Strings as numbers

by javajosh

HTML

<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css">
<script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
<input type="text" />
<button id="inc">Inc</button>
<button id="dec">Dec</button>

JavaScript

function inc(str){
    return str+1;
}

function dec(str){
    return str-1;
}

$("button")
    .button()
    .click(function(e) {
        var val = $('input').val();
        if (e.id === "inc") inc(val) else dec(val);
        $('input').val(val);
        
        e.preventDefault();
    });