Skip to content

Conversation

@addsoupbase
Copy link
Contributor

Added the implicit with statement wrapping that event handler attributes do, and the issues that come with it

Description

Mentioned a (lesser known?) feature of event handler attributes

Motivation

Additional details

Related issues and pull requests

Added the implicit `with` statement wrapping that event handler attributes do, and the issues that come with it
@addsoupbase addsoupbase requested a review from a team as a code owner December 11, 2025 07:39
@addsoupbase addsoupbase requested review from pepelsbey and removed request for a team December 11, 2025 07:39
@github-actions github-actions bot added Content:HTML Hypertext Markup Language docs size/s [PR only] 6-50 LoC changed labels Dec 11, 2025
> [!WARNING]
> While not visible by calling the `Function.prototype.toString()` method on the handler, event handler attributes will implicitly wrap code inside of 2 `with` statements, and may produce unexpected results. For example:
> ```html
Copy link
Contributor

Choose a reason for hiding this comment

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

[mdn-linter] reported by reviewdog 🐶

Suggested change
> ```html
>
> ```html

> ```html
> <div onclick="console.log(new URL(location))">Bad Example</div>
> ```
> Essentially becomes:
Copy link
Contributor

Choose a reason for hiding this comment

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

[mdn-linter] reported by reviewdog 🐶

Suggested change
> Essentially becomes:
>
> Essentially becomes:

> <div onclick="console.log(new URL(location))">Bad Example</div>
> ```
> Essentially becomes:
> ```js example-bad
Copy link
Contributor

Choose a reason for hiding this comment

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

[mdn-linter] reported by reviewdog 🐶

Suggested change
> ```js example-bad
>
> ```js example-bad

Comment on lines +1443 to +1444
> with(this.ownerDocument) {
> with(this) {
Copy link
Contributor

Choose a reason for hiding this comment

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

[mdn-linter] reported by reviewdog 🐶

Suggested change
> with(this.ownerDocument) {
> with(this) {
> with (this.ownerDocument) {
> with (this) {

@github-actions
Copy link
Contributor

Preview URLs

Flaws (36)

URL: /en-US/docs/Web/HTML/Reference/Attributes
Title: HTML attribute reference
Flaw count: 36

  • broken_links:
    • Can't resolve /en-US/docs/Web/HTML/Reference/Attributes/alt
    • Can't resolve /en-US/docs/Web/HTML/Reference/Attributes/autoplay
    • Can't resolve /en-US/docs/Web/HTML/Reference/Attributes/cite
    • Can't resolve /en-US/docs/Web/HTML/Reference/Attributes/colspan
    • Can't resolve /en-US/docs/Web/HTML/Reference/Attributes/controls
    • and 31 more flaws omitted

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.

1 participant