<style>
body { margin: 10px }
</style>
<body>
<script>
console.log(document.body.style.marginTop);
</script>
</body>
Question:
in firefox->console it shows : (an empty string)
, why?
window.getComputedStyle(document.body).marginTop
document.body.style
returns inline styles
You can do it like this:
var e = document.getElementsByTagName('body')[0],
style = window.getComputedStyle(e),
marginTop = style.getPropertyValue('margin-top');
console.log(marginTop);
Related question and answer, see here: Using JavaScript to read html / body tag margin-top
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