hasFeature (W3C DOM Core method)
var supported = document.implementation.hasFeature('Events', '2.0')
In the example above, the variable
supported will have
true if the implementation supports the DOM 2
Events module. Otherwise
supported will have the value
- feature (
The name of the feature to test, using one of the values defined in the DOM 2 Conformance list.
- version (
The DOM version to test. For DOM 2 this is always the value
2.0. If this argument is empty the method will return
trueif the feature is supported at any DOM level.
Test whether a specific feature of the DOM is implemented.
Here's a list of the features and DOM versions that can be tested:
||DOM 1 Core and XML|
||DOM 1 Core and HTML|
||DOM 2 Core|
||DOM 2 XML|
||DOM 2 HTML|
||DOM 2 Views module|
||DOM 2 Style Sheets module|
||DOM 2 CSS module|
||DOM 2 CSS 2 module|
||DOM 2 Events module|
||DOM 2 User-interface Events module|
||DOM 2 Mutation Events module|
||DOM 2 HTML Events module|
||DOM 2 Range module|
||DOM 2 Traversal module|
This method is essentially the same as
isSupported, except that it's only concerned with
whether a feature is supported by the DOM implementation, rather than
whether it's supported for a specific node.
This method is not at all useful in practise, because its data
cannot be trusted. It should only return
true if a
browser conforms to a particular module — and I reckon this should
mean, supports it fully without issues — but what we mostly find is
that it returns
true if a browser implements a
module at all, even if it's implemented only partially, or with
hasFeature tells us nothing about
whether a particular feature of the DOM can actually be used, so to
most intents and purposes it tells us nothing at all.
In fact I can't see how this method would ever be useful, even if
browsers were honest about it. To return
say you support something when you only partly support it is neither
helpful nor true, yet to return
false might suggest
that you don't support it at all, which is equally unhelpful and
The best way to establish support for something is to use feature detection (coming soon!).
true if the feature is supported by this
Internet Explorer 5.5 in HTML this method is
not available because the
object itself is undefined.
The following notes are an overview of how this method returns in different browsers, but it isn't really a summary of support — the method works correctly, it's just that its data isn't necessarily reliable.
Both Opera and
everything, even though they blatantly don't implement every module
fully (and for Safari in some cases, barely at all).
Internet Explorer in HTML only returns
true for DOM 1 HTML. Internet Explorer
in XML only returns
true for DOM 1
XML. This is close to being the truth, but not completely, since in
both cases the modules are not fully supported by IE.
for everything except DOM 2 Mutation events and DOM 2 Traversal. This
reflects missing features in those modules, and so it's the most
honest of any browser, but it still doesn't tell the whole story given
that other modules have bugs in their implementation.
There are no comments yet.