The advantage of using addEventListener
over properties like onclick
is that you can attach as many event handlers as you'd like to on the element.
This also means that adding another event handler does not automatically remove the previously set event handlers, as that would defeat the purpose, you have to remove those manually with removeEventListener.
document.removeEventListener('mousemove', getCursorXY, false);