namespaceURI (W3C DOM Core property)
| Version | Depr. | Static | Read-only |
|---|---|---|---|
| DOM2 | No | No | Yes |
| IE5.5+ | FF1.5+ | SA1.3+ | OP9+ |
|---|---|---|---|
| Full | Full | Full | Full |
Example
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
</html>
The example above shows the bare bones of an XHTML document. We could then retrieve the root namespace like this:
var ns = document.documentElement.namespaceURI;
If the document is in XHTML mode1 then the
ns variable will have the value
http://www.w3.org/1999/xhtml; for HTML mode2 it will be
null.
Description
The namespace URI of an Element or Attr node. For other
nodes, or elements or attributes created with a DOM 1 method that isn't
namespace aware (such as createElement),
or nodes with no namespace, this property is null.
This should not be a computed value or lookup of the namespace an element should have, it should be the literal value that it does have.
An Element node can
inherit its namespace from an ancestor. However Attr nodes do not inherit a namespace from the element
they're attached to — if an attribute does not have an explicitly defined
namespace then it simply has no namespace.
This property is readonly.
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 |
| Full | Full | Full | Full | Full | Full | Full | Full | Full | Full | Full |
Since namespaceURI is an XML construct, it's
only reasonable to judge its behavior in terms of XML (either on HTML
pages in XHTML mode3, or pure XML). The
behavioral variations of browsers in HTML mode4 are documented
here for interest and reference, but the support summary table above
does not consider this behavior (ie. if the property is fully
supported in XML then it's considered to be fully supported, with no
notes).
Internet Explorer in HTML doesn't implement this property (it returns undefined).
Safari 3 in HTML mode returns the XHTML namespace for all HTML elements, even in documents that aren't XHTML (eg. HTML 4).
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.