moving an element in JS

To move an element by changing it’s top value, the element can’t have a static position (the default). You’ll need to change the position to absolute, relative, fixed, etc…. Get the current top, left, etc… using Element#getBoundingClientRect, which will give you the correct initial value, and save you the need to parse a string. Since top needs to have a unit (px, em, … Read more

addEventListener vs onclick

Both are correct, but none of them are “best” per se, and there may be a reason the developer chose to use both approaches. Event Listeners (addEventListener and IE’s attachEvent) Earlier versions of Internet Explorer implement javascript differently from pretty much every other browser. With versions less than 9, you use the attachEvent[doc] method, like … Read more