add style javascript
// Bad:
element.setAttribute("style", "background-color: red;");
// Good:
element.style.backgroundColor = "red";
add style javascript
// Bad:
element.setAttribute("style", "background-color: red;");
// Good:
element.style.backgroundColor = "red";
how to change style of an element using javascript
<html>
<body>
<p id="p2">Hello World!</p>
<script>
document.getElementById("p2").style.color = "blue";
</script>
<p>The paragraph above was changed by a script.</p>
</body>
</html>
javascript style an element
// Getting the element first
var myElement = document.querySelector("#myElement");
// examples for updating styles
myElement.style.color = "blue";
myElement.style.backgroundColor = "red";
how to change css using javascript
document.getElementById("myText").className = "anyNewClass"
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us