jquery / jquery/api.jquery.com

Wrong return value of offset method for hidden/disconnected elements

Open
#1,197 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
325
Forks
260
PR merge metrics
No merged PRs in 30d

Description

The jQuery docs state, that

While it is possible to get the coordinates of elements with visibility:hidden set, display:none is excluded from the rendering tree and thus has a position that is undefined.

The return value of undefined was changed a few years ago in https://github.com/jquery/jquery/pull/2396 due to https://github.com/jquery/jquery/issues/2310. The tests are here.
Now a value of { top: 0, left: 0 } is returned instead (https://github.com/jquery/jquery/blob/a684e6ba836f7c553968d7d026ed7941e1a612d8/src/offset.js#L88)
and undefined is only returned for an empty jQuery object (https://github.com/jquery/jquery/blob/a684e6ba836f7c553968d7d026ed7941e1a612d8/src/offset.js#L79).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked API offset documentation, test/unit/offset.js, and src/offset.js in the referenced jQuery history. Confirm the intended return value for hidden, display:none, and disconnected elements, then make the relevant documentation or behavior consistent and verify the offset tests cover it.

Written by the indexing model from the issue text.

Assessment

Tech stack
jquery
Domain
documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.