javascript-tutorial / javascript-tutorial/en.javascript.info
Error description with element hidden check in "Element size and scrolling"
- Dominant language
- HTML
- Stars
- 25.5k
- Forks
- 4k
- PR merge metrics
- No merged PRs in 30d
Description
The tutorial said:
> Geometry properties are calculated only for displayed elements.
>
> If an element (or any of its ancestors) has display:none or is not in the document, then all geometry properties are zero (or null for offsetParent).
>
> For example, offsetParent is null, and offsetWidth, offsetHeight are 0 when we created an element, but haven’t inserted it into the document yet, or it (or it’s ancestor) has display:none.
>
> We can use this to check if an element is hidden, like this:
>
> ```js
> function isHidden(elem) {
> return !elem.offsetWidth && !elem.offsetHeight;
> }
> ```
But, what if the hidden element is hidden by setting the `width` to `0`, not the `height`? 😀
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the “Element size and scrolling” tutorial section and review the quoted geometry-properties explanation and isHidden example. Clarify how the example behaves when an element has zero width, and ensure the finished text accurately explains the hidden-element check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100