KillerSites Blog

Mobile

The Death of the JavaScript onMouseover

November 11, 2014

Hi!

In JavaScript, you have a bunch of events that you can tell the web browser to watch for. Here is a short list:

  • onclick
  • onmouseover
  • onmousedown

… There are many more. The proper nerd-term for all these is ‘event listeners’ – they ‘listen’ for events to happen and when they do (ex: someone clicks on a something,) you can have JavaScript fire off some function.

Event Attributes

Instead of using JavaScript to apply eventlisteners (using the addEventListener() method) to tags on your page, you can simply use HTML event attributes. For example:

<p onclick="aFunction()">
This is some text.
</p>

In the above code, I tell the browser that if someone clicks on the paragraph tag, that the ‘aFunction’ function should be activated. Nerds will refer to this as  ‘calling a function’ instead of activating.

The Death of onMouseover?

The onMouseover event listener ‘listens’ for someone to hover their mouse over the element (HTML tag) that it is bound to – like what we did with the paragraph tag above and the onclick event.

It’s a sweet effect and works on all the browsers, except it doesn’t work on mobile devices – that sucks! You have to remember that within a few years, more than 50% of the Web’s traffic will be mobile traffic – people using smartphones and tablets.

Basically, that means you should probably not use onMouseover event listeners.

Stefan Mischook
KillerSites.com

read more