Skip to content

Document that addClass and removeClass change the property #813

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

AurelioDeRosa
Copy link
Member

Fixes gh-312

@AurelioDeRosa
Copy link
Member Author

@agcolom @kswedberg Fixed! Thank you for the feedback.

@@ -19,6 +19,7 @@
<desc>Adds the specified class(es) to each element in the set of matched elements.</desc>
<longdesc>
<p>It's important to note that this method does not replace a class. It simply adds the class, appending it to any which may already be assigned to the elements.</p>
<p><code>.addClass()</code> manipulates the property of the selected elements, not the attribute. Once the property is changed, it's the browser that updates the <code>class</code> attribute accordingly. An implication of this behavior is that this method only works for documents with HTML DOM semantics (e.g., not pure XML documents).</p>
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it makes sense to also mention which property we're actually talking about, instead of just "the property"

Copy link
Member

Choose a reason for hiding this comment

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

@arthurvr, @AurelioDeRosa: 👍 to specifying the property. Maybe something like this?…

The .addClass() method manipulates the className property of the selected elements, not the class attribute. Once the property is changed, it's the browser that updates the attribute accordingly.

Copy link
Member

Choose a reason for hiding this comment

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

Note also that behavior will change in jQuery 3.0, where we will set the class attribute instead of the className property for better SVG support: jquery/jquery#2199

@AurelioDeRosa
Copy link
Member Author

PR updated. @gibson042 I'll open a separate issue for that and create a different PR if you agree. This way we can merge it into the relevant branch.

@gibson042
Copy link
Member

👍

@AurelioDeRosa
Copy link
Member Author

Anyone keen for a final review of this?

@dmethvin
Copy link
Member

LGTM, and we will revisit it when 3.0 lands.

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.

7 participants