namespaces collection
Represents a collection of namespaces that have 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:
Properties that reference the object:
| object.namespaces |
Related objects:
|
Possible members:
Properties:
Returns an integer that specifies the number of namespace objects in the current collection.
This property is read-only. |
Methods:
[nameOrIndex] |
Returns an object from the current collection by name or index.
Parameters:
Return value:
Returns a namespace object.
|
||||||||||||||||||||||||||||||
add (name, URN [, URL]) |
Adds a new namespace to the current collection.
Parameters:
Return value:
Returns the newly created namespace object
|
||||||||||||||||||||||||||||||
item (nameOrIndex) |
Returns an object from the current collection by name or index.
Parameters:
Return value:
Returns a namespace object.
|
Example HTML code 1:
This example illustrates the use of the namespaces collection:
|
|||||
<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?
|
Example HTML code 2:
This example is equivalent to the previous one, but it uses the add method to declare a namespace:
|
|||||
<html> <head> <script type="text/javascript"> var namespace = document.namespaces.add ("myNS", "http://help.dottoro.com/NS", "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?
|
External links:
User Contributed Comments