Skip to main content

Bug Tracker

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

http://jsbin.com/isevac/2/

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.

Attachments (0)
Change History (2)

Changed May 27, 2013 02:58PM UTC by dmethvin comment:1

jQuery always uses the .className **property** which is an empty string by default. We don't touch the class **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

Changed May 27, 2013 02:59PM UTC by dmethvin comment:2

resolution: → notabug
status: newclosed