Skip to content

attr: Document attr(key, null) to remove attribute #853

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

Closed
wants to merge 3 commits into from

Conversation

jugglinmike
Copy link
Contributor

In addition, introduce the null value type to more completely describe
the attr method's signature.

jQuery implements explicit support for this behavior [1]:

if ( value === null ) {
  jQuery.removeAttr( elem, name );
  return;
}

and also maintains unit tests to verify it [2]:

jQuery( "#name" ).attr( "name", null );
assert.equal( jQuery( "#name" ).attr( "name" ), undefined, "Remove name attribute" );

Fixes gh-523

[1] https://github.com/jquery/jquery/blob/1823a715660a5f31dd7e05672e9ad020066256a9/src/attributes/attr.js#L55-L58
[2] https://github.com/jquery/jquery/blob/1823a715660a5f31dd7e05672e9ad020066256a9/test/unit/attributes.js#L283-L284

In addition, introduce the `null` value type to more completely describe
the `attr` method's signature.

jQuery implements explicit support for this behavior [1]:

    if ( value === null ) {
      jQuery.removeAttr( elem, name );
      return;
    }

and also maintains unit tests to verify it [2]:

    jQuery( "#name" ).attr( "name", null );
    assert.equal( jQuery( "#name" ).attr( "name" ), undefined, "Remove name attribute" );

Fixes jquerygh-523

[1] https://github.com/jquery/jquery/blob/1823a715660a5f31dd7e05672e9ad020066256a9/src/attributes/attr.js#L55-L58
[2] https://github.com/jquery/jquery/blob/1823a715660a5f31dd7e05672e9ad020066256a9/test/unit/attributes.js#L283-L284
@dmethvin
Copy link
Member

I suppose the explicit new Null type is better for consumers like DefinitelyTyped that need such precision. LGTM!

@@ -147,7 +147,8 @@ The title of the emphasis is:<div></div>
<argument name="value">
<type name="String"/>
<type name="Number"/>
<desc>A value to set for the attribute.</desc>
<type name="Null"/>
<desc>A value to set for the attribute. If <code>null</code>, the specified attribute will be removed (as in <a href="/removeAttr/">.removeAttr()</a>).</desc>
Copy link
Member

Choose a reason for hiding this comment

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

Can you surround removeAttr() with the code tag?

@jugglinmike
Copy link
Contributor Author

All set, @AurelioDeRosa

@AurelioDeRosa
Copy link
Member

👍

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

Successfully merging this pull request may close these issues.

4 participants