X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

HTML DOM setNamedItem() Method

Attribute Object Reference Attribute Object

Example

Set a H1's class attribute:

var btn = document.getElementsByTagName("H1")[0];
var typ = document.createAttribute("class");
typ.value = "democlass";
btn.attributes.setNamedItem(typ);

Before setting the attribute:

Hello world

After setting the attribute:

Hello world


Try it yourself »


Definition and Usage

The setNamedItem() method adds the specified node to the nodeMap.

If the node allready exists, it will be replaced, and the replaced node will be the return value, otherwise the return value will be null.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

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


Syntax

namednodemap.setNamedItem(node)

Parameters

Parameter Type Description
node Node object Required. The node you want to add/replace in the namedNodeMap collection

Return Value

Type Description
Node object The replaced node, if any, otherwise null

Technical Details

DOM Version Core Level 1


Attribute Object Reference Attribute 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