I'm having trouble retrieving the "marginTop" style property from the <html>
and <body>
tags. While Chrome developer tools shows that margin-top is being set via in-HTML CSS:
<style type="text/css" media="screen">
html { margin-top: 28px !important; }
* html body { margin-top: 28px !important; }
</style>
Unfortunately, my attempts to access this property using pure JavaScript have been unsuccessful. When I try code like this:
console.debug(document.getElementsByTagName('html')[0].style.marginTop);
console.debug(document.getElementsByTagName('body')[0].style.marginTop);
I receive empty strings for both cases.
Although jQuery's offset()
function can detect margins correctly, I am unable to use jQuery in this particular scenario. Can someone offer guidance on how to successfully read the top margin property from the html and body elements using only JavaScript?