Hover Effect in Javascript (like in FireBug)
Or: Making a Select element effect.
I’ve been trying to create an element selection tool for Javascript.
The effect would be similar to FireBug (for those who know) -
I just wanted to highlight whichever element the user has his mouse on.
This proved to be more difficult than I thought.
I started with this short script:
|
|
(working example)
This seem to fail when going into child elements, where the parent element didn’t trigger
the “unhover” event (and thus stayed highlighted).
After a bit of tinkering, I wrote the following solution:
|
|
(working example)
There's not much need for clarification, as most of it is written in the comments.
Of course, you could have an extra Highlight function
(to actually do something with the current selected element), and what-not.
I just wanted to show the (relatively) hard part.
I wish there was an easier way to do this (not that this is such a bad solution).
Until next time!