Couldn't find here at Stackoverflow.
How can I add additional attribute to an element?
I need this
<div id="test"></div>
to be
<div id="test test2"></div>
document.getElementById("test").setAttribute("id", "test2")
sets to
<div id="test2"></div>
EDIT: the question provided was different question and not about class.
Try to read the attribute by using the
getAttribute
and then con-cat the new value at the end like this:EDIT
Just keep in mind to avoid doing this with the ID attribute. You can do it with almost any other attribute though.
Example with the class attribute