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

26th Apr 2022, 7:44 PM
Margaret Guzman
Margaret Guzman - avatar
2 Antworten
+ 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;
27th Apr 2022, 9:40 PM
ODLNT
ODLNT - avatar
0
I don't have the answer, but I tested to print the length and pos has a length of 0.
26th Apr 2022, 8:04 PM
Stefanoo
Stefanoo - avatar