Easy Tutorial
❮ Prop Link Rev Jsref Strike ❯

HTML DOM setNamedItem() Method

Attribute Object

Example

Set the class attribute of H1:

Before setting the attribute:

Hello world

After setting the attribute:

Hello world


Definition and Usage

The setNamedItem() method is used to add a specified node.

If the node already exists, it will be replaced and the value of the replaced node will be returned; otherwise, it will return null.


Browser Support

All major browsers support the setNamedItem() method.


Syntax

Parameters

Parameter Type Description
node Node Object Required. The node you want to replace in the node list.

Return Value

Type Description
Node Object Returns the replaced node; if no replacement occurs, returns null.

Technical Details

| DOM Version | Core Level 1 | | --- | --- |


Attribute Object

❮ Prop Link Rev Jsref Strike ❯