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.

Syntax:

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

Possible members:

Properties:
name
Returns the local name of a namespace.
readyState
Returns a string value that represents the state of the object.
urn
Returns the Uniform Resource Name (URN) of a namespace.
Methods:
attachEvent
Registers an event handler function (event listener) for the specified event on the current object.
detachEvent
Removes the specified event handler from the current element that was registered earlier with the attachEvent method.
doImport
Imports the specified behavior file into the current namespace.
Events:
onreadystatechange
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:
Code
hover.htc
<html xmlns:myNS="http://help.dottoro.com/NS">
<head>
    <script type="text/javascript">
        var namespace = document.namespaces("myNS");
        namespace.doImport("hover.htc");

        function GetNSInfo () {
            var namespace = document.namespaces["myNS"];
            alert ("The name of the namespace is " + namespace.name);
            alert ("The URN of the namespace is " + namespace.urn);
        }
    </script>
</head>
<body>
    <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>
</body>
</html>
Did you find this example helpful? yes no

Related pages:

External links:

User Contributed Comments

Post Content

Post Content