+ 1
Get CSS value with JavaScript
How would I get the value of a CSS attribute on an element with vanilla JavaScript? I have tried: const x = document.getElementById("arrow") if (x.style.left = "100px") { console.log(“Hello”) } I have also tried replacing “100px” with 100, but it still cannot read the property of null. Here’s my HTML body: <div id="arrow"></div> Here’s the CSS: #arrow { width: 6px; height: 100px; left: 100px; position: absolute; } Thank you!
2 Réponses
+ 2
i don't know why but while sending u answer it is showing
something went wrong
so i have made a code (with explanation )
u can using
1. cssText to get only inline style
2. getComputedStyle
https://code.sololearn.com/W56FK2ekeorM
+ 2
Maybe you were looking for this one
https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle