
- HTML Home
- HTML Roadmap
- HTML Introduction
- HTML History & Evolution
- HTML Editors
- HTML Basic Tags
- HTML Elements
- HTML Attributes
- HTML Headings
- HTML Paragraphs
- HTML Fonts
- HTML Blocks
- HTML Style Sheet
- HTML Formatting
- HTML Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - Document Object Model (DOM)
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - DOM Element setAttributeNode() Method
The HTML DOM Element setAttributeNode() method is used to add (or define) an attribute node to a specific element and update any existing attribute node with the same name.
An attribute node in the Document Object Model (DOM) represents an attribute of an element. Attributes provide additional information about an element.
Syntax
Following is the syntax of the HTML DOM Element setAttributeNode() method −
element.setAttributeNode(newAttrNode);
Parameters
This method accepts a single parameter as mentioned below:
Parameter | Description |
---|---|
newAttrNode | The new node you want to define for the particular element. |
Return Value
This method does not always return a value; instead, it sets a new attribute node value for the element. However, if an attribute is updated, it returns an 'Attr' object that holds the updated attribute node.
Example 1: Setting Class Attribute Node on Div Element
The following program demonstrates using the HTML DOM Element setAttributeNode() method. It adds (sets) the class attribute node on a Click button to set the class attribute to a div element. The above program adds a class attribute node to a Following is another example of the HTML DOM Element setAttributeNode() method. We use this method to update the existing attribute node of an element − This is a paragraph element. Click the below button to update attribute node When the program is executed, it updates the existing attribute node once the button is clicked. Element
In the example below, we use this function to add an id attribute node to a element: Click button to set the id attribute to a "p" element. The above program will add an "id" attribute node to a "p" element.
HTML DOM Element setAttributeNode() Method
Example 2: Updating the Attribute Node
Example 3: Setting Id Attribute Node on
HTML DOM Element setAttributeNode() Method
Supported Browsers
Method
setAttributeNode()
Yes
Yes
Yes
Yes
Yes