Welcome aboard! We are happy you are here and wish you good net-raft!
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<style>
div {
width: 30px;
height: 30px;
background: red;
position: relative;
}
</style>
<script>
$(document).ready(function () {
$(document).keydown(function (e) {
if( !$("div").is(':animated') ) {
var keyCode = e.which || e.keyCode;
switch (e.which) {
case 37:
$("div").animate({ 'marginLeft': "-=10px" }); //left arrow key
break;
case 38:
$("div").animate({ 'marginTop': "-=10px" }); //up arrow key
break;
case 39:
$("div").animate({ 'marginLeft': "+=10px" }); //right arrow key
break;
case 40:
$("div").animate({ 'marginTop': "+=10px" }); //bottom arrow key
break;
}
}
});
});
</script>
</head>
<body>
</p>
<div></div>
</body>
</html>
The most helpful JQUERY solutions