0
Q:

style an element with javascript

// Here are two different ways
document.getElementById("myH1").style.color = "red";
element.style.backgroundColor = "red";   // set the background color of an element to red
6
// Getting the element first
var myElement = document.querySelector("#myElement");

// examples for updating styles
myElement.style.color = "blue";
myElement.style.backgroundColor = "red";
1
document.getElementById("myH1").style.color = "red";
1

New to Communities?

Join the community