Skip to content

Commit 1436296

Browse files
committed
Docs: Improve the solution for boolean-attributes
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)
1 parent 562c10a commit 1436296

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

warnings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ This is _not_ a warning, but a console log message the plugin shows when it firs
125125

126126
**Cause**: When calling `.attr( name, value )` with any non-`false` non-`null` `value`, jQuery would actually set it to `name`. Similarly, regardless of the actual value, `.attr( name )` used to return `name` lowercased. This behavior is deprecated.
127127

128-
**Solution**: Always set boolean attributes to their names, whether when using jQuery (`.attr( name, name )`), native APIs (`.setAttribute( name, name )`) or directly in HTML (`<input checked="checked">`).
128+
**Solution**: Always set boolean attributes to their names, whether when using jQuery (`.attr( name, name )`), native APIs (`.setAttribute( name, name )`) or directly in HTML (`<input checked="checked">`). Avoid using the `.attr( name )` getter on boolean attributes, `.prop( name )` is preferred.
129129

130130
### \[attr-false\] JQMIGRATE: Setting the non-ARIA non-boolean attribute 'NAME' to false
131131

0 commit comments

Comments
 (0)