Q:

get style of element js

// 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
//to get all style
const style = getComputedStyle(element)
//or to get inline style
const style = element.style

const backgroundColor = style.backgroundColor
console.log(backgroundColor) // rgb(0, 0, 0)
0

New to Communities?

Join the community