Furry Yang
0
Q:

how to give css style in 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
// Bad:
element.setAttribute("style", "background-color: red;");
// Good:
element.style.backgroundColor = "red";
1
document.getElementById("myH1").style.color = "red";
1

New to Communities?

Join the community