JavaScript · Middle · Question 72 of 75
Why does el.style.width return an empty string for a width set in CSS?
- ✓Correct answer:
el.stylereflects only inline styles; usegetComputedStyle(el).widthfor the resolved value - 2The element hasn't loaded yet
- 3CSS widths are always
autoin JavaScript
Explanation
Computed styles return resolved values in pixels. Reading them forces style/layout calculation, so avoid doing it in tight loops.