I have a code something like this:
.position{
position:relative
}
<div class="position" id="position"></div>
document.getElementById('position').style.position
Result is " "
But if I put it directly on theHTML
<div id="position" style="position:absolute"></div>
Result is "absolute".
I have already made it run JS
when the document is loaded withDOMContentLoaded
I would like to know why, thank you very much!
If you need to get the styles applied " inline " to an element, you can use
element.style
.But, if you need to get the styles applied with
CSS
and " inline " to an element, you can usewindow.getComputedStyle()
Example:
I suggest you do it with JQuery as it makes the process easier this way