You are here: Reference > JavaScript > client-side > HTML DOM > methods > getNamedItemNS (attributes)
getNamedItemNS method (attributes)
9 | ||||
Returns the attribute node with the specified namespace and name from the current attributes collection.
Note: Internet Explorer supports the getNamedItemNS method from version 9, but only for HTML documents, not for XML documents.
To specify an attribute with namespace, use the setAttributeNS, setAttributeNodeNS or setNamedItemNS method.Syntax:
You can find the related objects in the Supported by objects section below.
Parameters:
Required. String that specifies the namespace URI of the attribute to retrieve. The namespace URI is case-sensitive. | |||||||
Required. String that specifies the name of the attribute to retrieve. The name is case-sensitive. |
Return value:
If no attribute exists with the specified namespace and name, it returns null, else it returns the matching attribute node.
Methods for attributes with namespaces:
Name | Browser | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
createAttributeNS |
|
Creates a new attribute node with the specified namespace and name. | ||||||||||
getAttributeNS |
|
Returns the value of the attribute with the specified namespace and name from the current element. | ||||||||||
getAttributeNodeNS |
|
Returns the attribute node with the specified namespace and name from the current element. | ||||||||||
getNamedItemNS |
|
Returns the attribute node with the specified namespace and name from the current attributes collection. | ||||||||||
hasAttributeNS |
|
Returns whether the current element has an attribute with the specified namespace and name or not. | ||||||||||
removeAttributeNS |
|
Removes the attribute with the specified namespace and name from the current element. | ||||||||||
removeAttributeNode | Removes the specified attribute node from the current element. | |||||||||||
removeNamedItemNS |
|
Removes the attribute with the specified namespace and name from the current attributes collection and returns the removed attribute node. | ||||||||||
setAttributeNS |
|
Adds an attribute with the specified namespace, name and value to the current element. | ||||||||||
setAttributeNodeNS |
|
Adds the specified attribute node to the current element. | ||||||||||
setNamedItemNS |
|
Adds the specified attribute node to the current attributes collection. |
Example HTML code 1:
This example illustrates the use of the getNamedItemNS method to get the 'dotto:color' value from the attributes collection:
|
|||||||
<head> <script type="text/javascript" src="ajax.js"></script> <script type="text/javascript"> var httpRequest = null; function SendRequest () { if (!httpRequest) { httpRequest = CreateHTTPRequestObject (); // defined in ajax.js } if (httpRequest) { // The requested file must be in the same domain that the page is served from. var url = "ns.xml"; httpRequest.open ("GET", url, true); // async httpRequest.onreadystatechange = OnStateChange; httpRequest.send (null); } } function OnStateChange () { if (httpRequest.readyState == 0 || httpRequest.readyState == 4) { if (IsRequestSuccessful (httpRequest)) { // defined in ajax.js Test_GetNamedItemNS (); } else { alert ("Operation failed."); } } } function Test_GetNamedItemNS () { var xmlDoc = ParseHTTPResponse (httpRequest); // defined in ajax.js if (!xmlDoc) return; var itemTags = xmlDoc.getElementsByTagName ("item"); var firstItemAttrs = itemTags[0].attributes; if (firstItemAttrs.getNamedItemNS) { var colorAttr = firstItemAttrs.getNamedItemNS ("http://help.dottoro.com/NS", "color"); alert ("the value of the color attribute is " + colorAttr.value); } else { alert ("Your browser doesn't support the getNamedItemNS method."); } } </script> </head> <body> <button onclick="SendRequest ()">Test the getNamedItemNS method</button> </body> |
|||||||
|
|||||||
Did you find this example helpful?
|
Supported by objects:
Related pages:
getNamedItem
createAttributeNS
getAttributeNS
getAttributeNodeNS
hasAttributeNS
removeAttributeNS
removeAttributeNode
removeNamedItemNS
setAttributeNS
setAttributeNodeNS
setNamedItemNS
createAttributeNS
getAttributeNS
getAttributeNodeNS
hasAttributeNS
removeAttributeNS
removeAttributeNode
removeNamedItemNS
setAttributeNS
setAttributeNodeNS
setNamedItemNS
External links:
User Contributed Comments