Side navigation
#13950 closed bug (notabug)
Opened May 27, 2013 01:15PM UTC
Closed May 27, 2013 02:59PM UTC
Class attribute instantiated upon .addClass(), but not removed upon .removeClass()
Reported by: | gabriel.schulhof@intel.com | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 2.0.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Basically,
var x = $( "<div></div>" ).appendTo( "body" ).addClass( "abc" ).removeClass( "abc" );
Leaves x with an attribute class="". This is counter-intuitive since the class of x is absent when addClass is first called, and removeClass is expected to completely revert the action of addClass.
jQuery always uses the
.className
**property** which is an empty string by default. We don't touch theclass
**attribute** at all.https://github.com/jquery/jquery/blob/26980c6ec96369bbaf87be1e405594df8ec3f0dc/src/attributes.js#L96
What the browser does with the attribute when the property is set back to an empty string is beyond the scope of what those methods accomplish. I'm not sure if it's defined by any spec, but if so it would be DOM0 since it goes back so far.
I've filed a docs ticket: https://github.com/jquery/api.jquery.com/issues/312