What is the CSS specificity when Javascript modifies CSS?
Such as:
document.getElementById("demo").style.color = "red";
Is it considered inline styling?
CSS specificity when Javascript modifies CSS?
Exactly the same as if you modified the CSS by editing the original source code instead of using JS.
document.getElementById("demo").style.color = "red";
In this case, you are modifying the styles attached directly to the element.
<div id="demo" style="color: red">
So maximum specificity. (count 1 if the declaration is from is a 'style' attribute rather than a rule with a selector)
If you had used JS to modify a ruleset, then the specificity would be different.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With