Skip to content

Add warning against using element IDs as global properties.#39422

Merged
Josh-Cena merged 7 commits intomdn:mainfrom
younisdev:patch-4
May 12, 2025
Merged

Add warning against using element IDs as global properties.#39422
Josh-Cena merged 7 commits intomdn:mainfrom
younisdev:patch-4

Conversation

@younisdev
Copy link
Copy Markdown
Contributor

Description

Add a warning about using element IDs as global properties on window object, and recommend best practices for safer DOM access.

Motivation

Help the readers follow modern standard and best practices when selecting and manipulating element using ID.

Additional details

None.

Related issues and pull requests

Fixes #39339

@younisdev younisdev requested a review from a team as a code owner May 6, 2025 20:30
@younisdev younisdev requested review from estelle and removed request for a team May 6, 2025 20:30
@github-actions github-actions bot added Content:HTML Hypertext Markup Language docs size/s [PR only] 6-50 LoC changed labels May 6, 2025
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented May 6, 2025

Preview URLs

(comment last updated: 2025-05-12 01:01:08)

Comment on lines +54 to +63
> For example, if we had an element with an `id="performance"`, the following code would've worked before the introduction of Performance in modern browsers:
>
> ```html
> <h3 id="performance"></h3>
>
> <script>
> performance.innerHTML = "Well Done!";
> performance.style.backgroundColor = "green";
> </script>
> ```
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest removing this because we can directly build upon the preamble example

younisdev and others added 2 commits May 7, 2025 15:14
Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
@github-actions github-actions bot added size/xs [PR only] 0-5 LoC changed and removed size/s [PR only] 6-50 LoC changed labels May 7, 2025
Copy link
Copy Markdown
Member

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you:)

@github-actions github-actions bot added size/s [PR only] 6-50 LoC changed and removed size/xs [PR only] 0-5 LoC changed labels May 12, 2025
@Josh-Cena Josh-Cena merged commit 96ad637 into mdn:main May 12, 2025
8 checks passed
@younisdev
Copy link
Copy Markdown
Contributor Author

younisdev commented May 12, 2025

Nice, thank you:)

Appreciate it! Thanks for the review!

wbamberg added a commit to wbamberg/content that referenced this pull request May 21, 2025
* upstream/main: (40 commits)
  Add a guide on xs-leaks (mdn#38977)
  chore: Link to child pages in SVG, URI section (mdn#39470)
  Correct page title for `Uint8Array.prototype.setFromHex()` (mdn#39494)
  Bump markdownlint-cli2 from 0.17.2 to 0.18.0 (mdn#39488)
  Add more documentation for sizes=auto (mdn#39464)
  css(fix): update 'shape()' page (mdn#39454)
  Expand Compression Dictionary format description (mdn#39441)
  Add username/password section to URLs guide (mdn#39487)
  Fix typos (mdn#39481)
  CSS: mask-position property description (mdn#39449)
  Adding @starting-style to CSS nesting at-rules (mdn#39473)
  feat(aria): Add short titles, format titles for roles (mdn#39472)
  Fix Circle Collision detection algorithm (mdn#39484)
  Add warning against using element IDs as global properties. (mdn#39422)
  Fix typos in web audio spatialization basics (mdn#39476)
  More Error Messages (mdn#39419)
  Add links to CSS sidebar (mdn#39445)
  css: add 'stretch' value examples (mdn#39451)
  chore: link to unlinked child pages (mdn#39469)
  Fix typos (mdn#39465)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:HTML Hypertext Markup Language docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Documentation does not warn against using element IDs as global properties

3 participants