I’m doing this output and it’s already running like I wanted it to. This is like moving a div using arrows keys, but my problem is when I press arrows key to move, the color grey div surpasses its own parent div. What I want to achieve is that the grey div would not be able to step outside its parent div (that has a red border), even if I continually press arrow keys.
This is demo jsFiddle
Any help?
Change your code to
Also add
position:relativeto the#centerSpaceDemo at http://jsfiddle.net/4bpgp/17/