Issue
Why does style.textDecoration contain an rgb value?
style = window.getComputedStyle(document.getElementById('gettextDecorationfrom'));
weight = style.textDecoration;
document.getElementById("results").innerText = style.textDecoration;
.myclass {
text-decoration:initial;
}
<div id="gettextDecorationfrom" class="myclass">
Test
</div>
<hr>
Result: <div id="results"></div>
I was expecting "initial" to be the result from this but was not expecting an rgb value to show up.
If underline is set the rgb value is also still there but just with 'underline' added, I don't understand why rgb is there in the first place?
style = window.getComputedStyle(document.getElementById('gettextDecorationfrom'));
weight = style.textDecoration;
document.getElementById("results").innerText = style.textDecoration;
.myclass {
text-decoration:underline;
}
<div id="gettextDecorationfrom" class="myclass">
Test
</div>
<hr>
Result: <div id="results"></div>
Can I remove the rgb value from text-decoration no matter what the value is?
Solution
Per the docs, text-decoration is a shorthand property. See: https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration
That means it contains multiple properties. Specifically, it contains text-decoration-line
, text-decoration-color
, text-decoration-style
, and text-decoration-thickness
. That's why you see the RGB value, because it includes color in the text-decoration
property.
If you just want the text-decoration-line property, then you can use textDecorationLine
, but that still will never give you initial
as you mentioned in your first example.
That's because getComputedStyle
does not return what is in the CSS; it returns the style that actually ends up getting applied the element. That's why it's called computed style. initial
is not a computed style, it's a value that instructs the browser to compute the style by using whatever the initial style was, which for text-decoration-line is none, as you can see here: https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration-line#formal_definition
If you want to get that initial
, you will have to actually inspect the stylesheet itself. See: https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet
Answered By - Instance Hunter
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.