0
Does setattribute function in js replaces the existing attributes and its values?
For example: I have class attribute with two values. Will the class attribute be replaced when i use setattribute for class?
7 Answers
+ 1
Pranay Sehgal no it doesn't replace them but
It will remove all previous class
And set a new value
For example :
Before
<div class="clas claz" ></div>
JS
Clas. SetAttribute("newClass")
After
<div class="newClass" ></div>
+ 1
Yes
+ 1
HTML DOM setAttribute() Method
https://www.w3schools.com/jsref/met_element_setattribute.asp
+ 1
HTMLElement.classList.add (YOUR_CLASS )
for info
"Element.classList - Web APIs | MDN" https://developer.mozilla.org/en-US/docs/Web/API/Element/classList
0
It replaces them?
0
Beauty kindly reply
0
Okay Beauty thanks is there any other method when i can use to add a new class rather than replacing them?