Answers for "how to change property of element in javascript"

2

html change attribute

element.setAttribute(name, value);


var d = document.getElementById("d1"); 
d.setAttribute("align", "center");
Posted by: Guest on July-21-2020
2

set property dom javascrpt

document.getElementsByTagName("H1")[0].setAttribute("class", "democlass");
Posted by: Guest on April-17-2020
0

set property js

There might not seem to be a difference with 'color' but consider:

element.style.backgroundColor = 'blue' // works
element.style['backgroundColor'] = 'blue' // works
element.style['background-color'] = 'blue' // does not work

element.style.setProperty('background-color','blue') // works
element.style.setProperty('backgroundColor','blue') // does not work
Posted by: Guest on July-27-2021

Code answers related to "how to change property of element in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language