HTML and CSS Reference
In-Depth Information
return dom.customEvents[event](element, listener);
}
return _addEventHandler(element, event, listener);
}
dom.addEventHandler = addEventHandler;
}());
The
mouseenter
implementation keeps track of whether the mouse is cur-
rently hovering the target element, and fires anytime a
mouseover
is fired and the
mouse wasn't previously hovering it. The method uses
dom.contains(parent,
child)
, which returns true if an element contains another. The try-catch pro-
tects against a bug in Firefox, which will sometimes provide an XUL element as
relatedTarget
. This can happen when mousing over for instance a scroll bar,
and unfortunately XUL elements throw exceptions on
any
property access. Addi-
tionally, the
relatedTarget
may be a text node, fetching its
parentNode
gets
us back on track.
To practice feature detection, I encourage you to take this method for a spin,
find more browser quirks, and smooth them over by detecting erroneous behavior
and correcting it.
Feature detection is a powerful tool in cross-browser scripting. It can allow many
features to be implemented for a very wide array of browsers; old, current, and future
ones. That does not necessarily mean that employing feature detection implies that
you should provide fallback solutions for any feature that may not be supported.
Sometimes, dropping support for old browsers can be a statement in itself, but we
should be able to do so without sniffing out the browsers we want to send down
the degradation path.
10.6.1 Moving Forward
If supporting a troublesome old browser, oh say Internet Explorer 6, costs more
than the benefits can defend, businesses sometimes actively decide to drop sup-
port. Doing so does not mean we should pretend “unsupported” browsers don't
exist. Using unobtrusive JavaScript and feature detection can ensure that when a
browser is no longer actively developed for, it will receive the usable but possibly