Dorward

Adding redundancy to CSS using JavaScript

19 February 2009

This is a favourite trick of some people

 onmouseover="this.style.cursor = 'pointer'" 

Why is this insane?

The cursor property sets the appearance of the mouse cursor when it is over the element in question. So this is saying:

When the mouse is over the element, set the mouse cursor for when the mouse is over the element to ‘pointer’.

Exactly the same effect (but without the overhead of the JavaScript function being fired whenever the mouse wanders over to the element) can be achieved with:

 style="cursor: pointer" 

(There are other issues with this code, such as the use of inline style and event handlers, and the consequences of using the pointer style on things that do not naturally have it, but this is a quick post and I won’t detail them here.)