0
Why does the pos variable contain nothing when logged in the console?
I am trying to store the top position of the div in the variable pos. It’s value is assigned in line 36 https://code.sololearn.com/WTJZYziMTk6N/?ref=app
2 Respuestas
+ 1
The style attribute is used to set and read inline css via the html element or javascript
<p style="color:green">This is a paragraph.</p>
let color = document.querySelector('p').style.color // 'green'
Neither div is using style attribute to set the inline css hence the absence of any value.
You can use the offsetTop property, This property will give the top position of the element relative to its parent.
var pos = elem.offsetTop;
0
I don't have the answer, but I tested to print the length and pos has a length of 0.