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";
JS change styles
// select element from DOM
const sample = document.getElementById("myid");
// or you can use *vars*
var sample = document.getElementById("myid");
// change css style
sample.style.color = 'red'; // Change color
// or (not recomended)
sample.style = "color: red"; //This changes all styles. NOT RECOMENDED
adding styling to element using javascript
var elem = document.querySelector('#some-element');
// Set color to purple
elem.style.color = 'purple';
// Set the background color to a light gray
elem.style.backgroundColor = '#e5e5e5';
// Set the height to 150px
elem.style.height = '150px';
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