There is an element that I need help with
<div id="square"></div>
This element has the ability to move around the document
var square = document.getElementById("square");
document.body.onkeydown = function(e) {
if (e.keyCode == 37) {left()}
if (e.keyCode == 38) {up()}
if (e.keyCode == 39) {right()}
if (e.keyCode == 40) {down()}
}
How can I create a function that prevents movement if the square
element is too close to the document border?
JSFiddle: https://jsfiddle.net/zutxyLsq/