Is there something equivalent to:
.setAttribute() that adds to the attribute something like:
.addToAttribute()
Instead of resetting the entire attribute value… it adds to the current value.
Heads up
The attribute could be anything: name, id, title… etc.
I need to add to any attribute at will and not just to the class
What I have
function one() {
body = document.body
div = document.createElement('div')
body.appendChild(div)
div.setAttribute("class", "blue")
div.setAttribute("name", "John")
div.setAttribute("id", "box")
}
one()
//should be
//name="John new value"
div.setAttribute("name", "new value")
// Is there something equivalent to .setAttribute()?
// Like .addToAttribue()?
console.log(document.getElementById('box'))
.blue {
width: 100px;
height: 100px;
background: red;
background: blue;
}
[name~="value"] {
border-radius: 50%;
}
What it should log
function one() {
body = document.body
div = document.createElement('div')
body.appendChild(div)
div.setAttribute("class", "blue")
div.setAttribute("name", "name")
div.setAttribute("id", "box")
}
one()
div.setAttribute("name", "John new value")
console.log(document.getElementById('box'))
.blue {
width: 100px;
height: 100px;
background: red;
background: blue;
}
[name~="value"] {
border-radius: 50%;
}