hasFeature (W3C DOM Core method)
| Version | Depr. | Static |
|---|---|---|
| DOM1 | No | No |
| IE6+ | FF1.5+ | SA1.3+ | OP9+ |
|---|---|---|---|
| Full | Full | Full | Full |
- Returns
Boolean
Example
var supported = document.implementation.hasFeature('Events', '2.0')
In the example above, the variable supported will have
the value true if the implementation supports the DOM 2
Events module. Otherwise supported will have the value
false.
Arguments
- feature (
DOMString) required The name of the feature to test, using one of the values defined in the DOM 2 Conformance list.
- version (
DOMString) required The DOM version to test. For DOM 2 this is always the value
2.0. If this argument is empty the method will returntrueif the feature is supported at any DOM level.
Description
Test whether a specific feature of the DOM is implemented.
Here's a list of the features and DOM versions that can be tested:
| Feature name | Version | Description |
|---|---|---|
XML |
1.0 |
DOM 1 Core and XML |
HTML |
1.0 |
DOM 1 Core and HTML |
Core |
2.0 |
DOM 2 Core |
XML |
2.0 |
DOM 2 XML |
HTML |
2.0 |
DOM 2 HTML |
Views |
2.0 |
DOM 2 Views module |
StyleSheets |
2.0 |
DOM 2 Style Sheets module |
CSS |
2.0 |
DOM 2 CSS module |
CSS2 |
2.0 |
DOM 2 CSS 2 module |
Events |
2.0 |
DOM 2 Events module |
UIEvents |
2.0 |
DOM 2 User-interface Events module |
MutationEvents |
2.0 |
DOM 2 Mutation Events module |
HTMLEvents |
2.0 |
DOM 2 HTML Events module |
Range |
2.0 |
DOM 2 Range module |
Traversal |
2.0 |
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
bugs.
Ultimately, 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 true and
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
untrue.
The best way to establish support for something is to use feature detection (coming soon!).
Return value
Returns
true if the feature is supported by this
implementation, otherwise false
Compatibility
| Internet Explorer | Firefox | Safari | Opera | |||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 5.5 | 6.0 | 7.0 | 1.5 | 2.0 | 3.0 | 1.3 | 2.0 | 3.0 | 9.0 | 9.5 |
| Partial | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full |
In
Internet Explorer 5.5 in HTML this method is
not available because the implementation
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
Safari return true for
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.
Firefox returns true
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.
User-contributed notes
There are no comments yet.
Add a note
To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.