X
HOME HTML5 CSS3 JAVASCRIPT SQL PHP5 JQUERY ANGULAR BOOTSTRAP3 XML MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

DOM Element setAttributeNodeNS() Method

Element Object Reference Element Object

The following code fragment uses the xml file: "booksnamespace.xml".

Example

Add a nationality attribute with the specified namespace, to the author element:

y=xmlDoc.createAttributeNS("http://www.w3.org/1999/xhtml","nationality");
y.value="english";
elmnt.setAttributeNodeNS(y);

Try it yourself »


Definition and Usage

The setAttributeNodeNS() method adds the specified attribute node to the element.

If the specified attribute already exists, this method replaces it.

Note: The setAttributeNodeNS method is an XML method, and will not work with HTML elements.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The setAttributeNodeNS() method is supported in all major browsers.

Note: This method is an XML DOM method, and will not work with HTML elements, However, Chrome and Safari supports this method with HTML elements as well.

Note: This method is not supported in Internet Explorer 9 and earlier versions.


Syntax

element.setAttributeNodeNS(attributenode)

Parameters

Parameter Type Description
attributenode Attr object Required. The attribute node you want to add

Return Value

Type Description
Attr object The replaced attribute node, if any, otherwise null

Technical Details

DOM Version Core Level 2


Element Object Reference Element Object


Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook