Node.namespaceURI

  • Revision slug: DOM/Node.namespaceURI
  • Revision title: Node.namespaceURI
  • Revision id: 131114
  • Created:
  • Creator: Nickolay
  • Is current revision? No
  • Comment /* Notes */

Revision Content

{{template.DomRef()}}

Summary

The namespace URI of the node, or null if it is unspecified (read-only).

Syntax

namespace = node.namespaceURI 
  • namespace is a string that represents the namespace URI of the specified node.

Example

In this snippet, a node is being examined for its localName and its namespaceURI. If the namespaceURI returns the XUL namespace and the localName returns "browser", then the node is understood to be a XUL <browser/>.

if (node.localName == "browser" && 
    node.namespaceURI == "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul") {
  // this is a XUL browser 
}

Notes

This is not a computed value that is the result of a namespace lookup based on an examination of the namespace declarations in scope. It is merely the namespace URI given at creation time.

For nodes of any nodeType other than ELEMENT_NODE and ATTRIBUTE_NODE, and nodes created with a DOM Level 1 method, such as document.createElement, the value of namespaceURI is always null.

You can create an element with the specified namespaceURI using the DOM Level 2 method document.createElementNS.

Per the Namespaces in XML specification, an attribute does not inherit its namespace from the element it is attached to. If an attribute is not explicitly given a namespace, it has no namespace.

Specification

DOM Level 2 Core: namespaceURI

DOM Level 2 Core: XML Namespaces

{{ wiki.languages( { "pl": "pl/DOM/element.namespaceURI" } ) }}

Revision Source

<p>
{{template.DomRef()}}
</p>
<h3 name="Summary"> Summary </h3>
<p>The namespace URI of the node, or <code>null</code> if it is unspecified (read-only).
</p>
<h3 name="Syntax"> Syntax </h3>
<pre class="eval"><i>namespace</i> = <i>node</i>.namespaceURI 
</pre>
<ul><li> <code>namespace</code> is a string that represents the namespace URI of the specified node.
</li></ul>
<h3 name="Example"> Example </h3>
<p>In this snippet, a node is being examined for its <a href="en/DOM/element.localName">localName</a> and its <code>namespaceURI</code>. If the <code>namespaceURI</code> returns the XUL namespace and the <code>localName</code> returns "browser", then the node is understood to be a XUL <code>&lt;browser/&gt;</code>. 
</p>
<pre>if (node.localName == "browser" &amp;&amp; 
    node.namespaceURI == "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul") {
  // this is a XUL browser 
}
</pre>
<h3 name="Notes"> Notes </h3>
<p>This is not a computed value that is the result of a namespace lookup based on an examination of the namespace declarations in scope. It is merely the namespace URI given at creation time.
</p><p>For nodes of any <a href="en/DOM/element.nodeType">nodeType</a> other than <code>ELEMENT_NODE</code> and <code>ATTRIBUTE_NODE</code>, and nodes created with a DOM Level 1 method, such as <a href="en/DOM/document.createElement">document.createElement</a>, the value of <code>namespaceURI</code> is always <code>null</code>.
</p><p>You can create an element with the specified <code>namespaceURI</code> using the DOM Level 2 method <a href="en/DOM/document.createElementNS">document.createElementNS</a>.
</p><p>Per the <a class="external" href="http://www.w3.org/TR/xml-names11/">Namespaces in XML</a> specification, an attribute does not inherit its namespace from the element it is attached to. If an attribute is not explicitly given a namespace, it has no namespace.
</p>
<h3 name="Specification"> Specification </h3>
<p><a class="external" href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-NodeNSname">DOM Level 2 Core: namespaceURI</a>
</p><p><a class="external" href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#Namespaces-Considerations">DOM Level 2 Core: XML Namespaces</a>
</p>{{ wiki.languages( { "pl": "pl/DOM/element.namespaceURI" } ) }}
Revert to this revision