user3781326
user3781326

Reputation: 9

Writing onmousemove event javascript a different way

I was wondering how I can write document.onmousemove a different way? Here is the code:

   document.onmousemove = something;

I can only seem to be able to run one function this way, how can I write it a different way?

Upvotes: 1

Views: 40

Answers (2)

Ry-
Ry-

Reputation: 225074

Using addEventListener:

document.addEventListener('mousemove', something, false);

For compatibility with IE8 and earlier, you can fall back on its attachEvent (mind the prefix, and you’ll have to use window.event instead of the argument):

document.attachEvent('onmousemove', something);

Upvotes: 2

Barmar
Barmar

Reputation: 781751

Since you're using , you can do it this way:

$(document).on("mousemove", something);
$(document).on("mousemove", somethingElse);

Upvotes: 2

Related Questions