Skip to content

Instantly share code, notes, and snippets.

@austintaylor
Created April 12, 2011 18:59
Show Gist options
  • Save austintaylor/916145 to your computer and use it in GitHub Desktop.
Save austintaylor/916145 to your computer and use it in GitHub Desktop.
Used this to track down a crazy JS bug one time. Still makes me smile.
var eventColors = {
mouseover: 'red',
mouseout: 'blue',
click: 'yellow'
}
var highlight = function(event) {
Event.stop(event);
element = Event.element(event);
Element.setStyle(element, {backgroundColor: eventColors[event.type]});
setTimeout(Element.setStyle.bind(null, element, {backgroundColor: ''}), 200);
}
Event.observe(window, 'load', function() {
Event.observe(document.body, 'mouseover', highlight.bindAsEventListener());
Event.observe(document.body, 'mouseout', highlight.bindAsEventListener());
Event.observe(document.body, 'click', highlight.bindAsEventListener());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment