Answers for "adding styles in js"

CSS
27

add style javascript

// Bad:
element.setAttribute("style", "background-color: red;");
// Good:
element.style.backgroundColor = "red";
Posted by: Guest on September-08-2020
1

add styles object js

document.getElementById("myElement").style.cssText = "display: block; position: absolute";
Posted by: Guest on November-07-2020

Browse Popular Code Answers by Language