javascript - what is the alternative to offsetLeft in internet-explorer (not work with me in ie) -
my question obvious, doesn't need clarify.
my code
document.onkeypress = function(evt) { var elem = document.getelementbyid('box'); evt = evt || window.event; var charcode = evt.charcode || evt.keycode; switch (charcode) { case 37: elem.style.position = 'absolute'; elem.style.left = parseint(elem.offsetleft - 10) + 'px'; elem.innerhtml = elem.offsetleft; break; case 38: elem.style.position = 'absolute'; elem.style.top = parseint(elem.offsettop - 10) + 'px'; elem.innerhtml = elem.offsettop; break; case 39: elem.style.position = 'absolute'; elem.style.left = parseint(elem.offsetleft + 10) + 'px'; elem.innerhtml = elem.offsetleft; break; case 40: elem.style.position = 'absolute'; elem.style.top = parseint(elem.offsettop + 10) + 'px'; elem.innerhtml = elem.offsettop; break; case 101: elem.style.position = 'relative'; elem.style.left = 0 + 'px'; elem.style.top = 0 + 'px'; break; default: } };
the previous example work fine in ff not work in ie.
what reason of offsetleft
, offsettop
don't work in ie.
there alternative internet-explorer or so, what's problem ?
try demo in jsfiddle.
i believe simple fix changing event listening keypress keydown
document.onkeydown = function(evt) {