In this shot, we will learn how to set a new attribute node in an HTML element.
The setAttributeNode()
method sets the attribute
Let’s write a code to set an attribute node to an element.
'new'
with a color property to ‘yellow’.DIV
element with id div
.change()
function, which will be called when the user clicks on the button.change()
function will be called when a user clicks the button from the HTML page.class
.div
element with id div
.setAttributeNode()
method to add the new attribute Node in the DIV
element.When we click the button, the color of the DIV
element changes, which means the new CSS class has been successfully added to the selected element.