I have applied a font-size:
style to my html
tag via stylesheet. I would like to retrieve it in javascript.
I have tried doing document.getElementsByTagName("html")[0].style
and I end up retrieving the styles with no values.
I have applied a font-size:
style to my html
tag via stylesheet. I would like to retrieve it in javascript.
I have tried doing document.getElementsByTagName("html")[0].style
and I end up retrieving the styles with no values.
The html
element can be referred by document.documentElement
Try the following:
var elem = window.getComputedStyle(document.documentElement);
var fontSize = elem.fontSize;
console.log(fontSize);
html{
font-size: 20px;
}
<html>
<head>
</head>
<body>
</body>
</html>
Please try the following:
let elem = document.getElementsByTagName("html")[0];
console.log(window.getComputedStyle(elem, null).getPropertyValue("font-size"));