You are here: Reference > JavaScript > client-side > HTML DOM > objects > namespace

namespace object

Browser support:
Represents a namespace that has been declared for custom elements in HTML.
Namespaces are useful to create custom elements, with custom functionality in HTML. To create a custom element, declare a namespace with the xmlns attribute or with the add method of the namespaces collection, add behaviors to it with the doImport method and use the local name of your namespace as a prefix for custom elements.
These kind of namespaces are different from namespaces in XML documents. If you need information about namespace handling in XML documents, please see the pages for the createAttributeNS and createElementNS methods.


Methods that return the object:
namespaces.add (name, URN [, URL])
namespaces.item (nameOrIndex)

Possible members:

Returns the local name of a namespace.
Returns a string value that represents the state of the object.
Returns the Uniform Resource Name (URN) of a namespace.
Registers an event handler function (event listener) for the specified event on the current object.
Removes the specified event handler from the current element that was registered earlier with the attachEvent method.
Imports the specified behavior file into the current namespace.
Occurs when the load state of the data that belongs to an element or a HTML document changes.

Example HTML code 1:

This example illustrates the use of the namespace object:
<html xmlns:myNS="">
    <script type="text/javascript">
        var namespace = document.namespaces("myNS");

        function GetNSInfo () {
            var namespace = document.namespaces["myNS"];
            alert ("The name of the namespace is " +;
            alert ("The URN of the namespace is " + namespace.urn);
    <myNS:span>Move the mouse over this text (element with behavior)</myNS:span><br />
    <span>Move the mouse over this text (element without behavior)</span>
    <br /><br />
    <button onclick="GetNSInfo ()">Get information about a namespace</button>
Did you find this example helpful? yes no

Related pages:

External links:

User Contributed Comments

Post Content

Post Content