Feature testing (sometimes called capability testing) is a powerful technique for coping with incompatibilities. If you want to use a feature or capability that may not be supported by all browsers, include code in your script that tests to see whether that feature is supported. If the desired feature is not supported on the current platform, either do not use it on that platform or provide alternative code that works on all platforms.
For example, there is code that looks like this:
if (element.addEventListener) { // Test for this W3C method before using it
element.addEventListener("keydown", handler, false);
element.addEventListener("keypress", handler, false);
}
else if (element.attachEvent) { // Test for this IE method before using it
element.attachEvent("onkeydown", handler);
element.attachEvent("onkeypress", handler);
}
else { // Otherwise, fall back on a universally supported technique
element.onkeydown = element.onkeypress = handler;
}