JavaScript: Move Element

by MythOfEchelon

HTML

<!-- This is just my HTML5 template. Make sure you set this up correctly for your personal needs. -->

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        
        <style>
            * {
                margin: 0;
                padding: 0;
            }
        
            html {
                font: 16px "Segoe UI", "Segoe WPC", Helvetica, Arial, "Arial Unicode MS", Sans-Serif;
            }
            
            div {
                float: left;
            }
            
            #avatar {
                position: absolute;
                width: 75px;
                height: 75px;
                background-color: red;
            }
            
            
        </style>
        
        <script>
            document.onreadystatechange = function(){
                if (document.readyState === "complete"){
                    /* 
                       Page is fully loaded and ready for interaction.
                       Using this method circumvents issues caused by attempted interaction with uninitialized objects.
                    */
                    
                    attachEventListeners();
                }
            }
            
            function attachEventListeners(){
            document.getElementsByTagName("body").onkeypress = function(){alert("Test")} //function(){move();};
                console.log("Added");
            }
            
            function move(){
                console.log("move()");
                var key = event.keyCode;
                console.log(key);
                /*
                    Left  = 37
                    Up    = 38
                    Right = 39
                    Down  = 40
                    List  = http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
                */
                
                if (key == 37){
                    console.log("Left");
...