Skip to content

Docs: Improve the solution for boolean-attributes #588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2025

Conversation

mgol
Copy link
Member

@mgol mgol commented Aug 11, 2025

Because jQuery 4.0.0 will not transform attribute values in the getter, the following code changes between jQuery 3.x & 4.x:

$( elem ).prop( "disabled", true );
$( elem ).attr( "disabled" );

In jQuery 3.x, the reported attribute value is "disabled", in jQuery 4.x it will be an empty string. This may create issues when migrating so Migrate patches and warns against it.

Add a recommendation to avoid using the .attr() getter on boolean attrs.

Because jQuery 4.0.0 will not transform attribute values in the getter, the
following code changes between jQuery 3.x & 4.x:

```js
$( elem ).prop( "disabled", true );
$( elem ).attr( "disabled" );
```

In jQuery 3.x, the reported attribute value is `"disabled"`, in jQuery 4.x it
will be an empty string. This may create issues when migrating so Migrate
patches and warns against it.

Add a recommendation to avoid using the `.attr()` getter on boolean attrs.
@mgol mgol added this to the 4.0.0 milestone Aug 11, 2025
@mgol mgol self-assigned this Aug 11, 2025
@mgol mgol requested a review from timmywil August 11, 2025 22:13
@mgol mgol merged commit e61af3f into jquery:main Aug 12, 2025
13 checks passed
@mgol mgol deleted the boolean-attributes-solution-improvement branch August 12, 2025 19:49
@mgol mgol removed the Needs review label Aug 12, 2025
mgol added a commit that referenced this pull request Aug 12, 2025
Because jQuery 4.0.0 will not transform attribute values in the getter, the
following code changes between jQuery 3.x & 4.x:

```js
$( elem ).prop( "disabled", true );
$( elem ).attr( "disabled" );
```

In jQuery 3.x, the reported attribute value is `"disabled"`, in jQuery 4.x it
will be an empty string. This may create issues when migrating so Migrate
patches and warns against it.

Add a recommendation to avoid using the `.attr()` getter on boolean attrs.

Closes gh-588

(cherry picked from commit e61af3f)
@mgol mgol modified the milestones: 4.0.0, 3.6.0 Aug 12, 2025
@mgol
Copy link
Member Author

mgol commented Aug 12, 2025

Landed on main in e61af3f and on 3.x-stable in 1436296.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants