move box around with keys

by Neal

HTML

<div id="char"></div>

CSS

#char {
    position: fixed;
    width: 100px;
    height: 100px;
    background: blue;
    top: 0;
    left: 0;
}

JavaScript

$(document).keydown(function(e) {
    if (e.keyCode == 39) {
        //do something
        $("#char").animate({
            'left': '+=10'
        }, 1);
    }
    if (e.keyCode == 37) {
        //do something
        $("#char").animate({
            'left': '-=10'
        }, 1);
    }

    if (e.keyCode == 38) {
        //do something
        $("#char").animate({
            'top': '-=10'
        }, 1);
    }
    if (e.keyCode == 40) {
        //do something
        $("#char").animate({
            'top': '+=10'
        }, 1);
    }
})