Bug Tracker

Opened 9 years ago

Closed 9 years ago

#13950 closed bug (notabug)

Class attribute instantiated upon .addClass(), but not removed upon .removeClass()

Reported by: [email protected] 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.

Change History (2)

comment:1 Changed 9 years ago by dmethvin

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

comment:2 Changed 9 years ago by dmethvin

Resolution: notabug
Status: newclosed
Note: See TracTickets for help on using tickets.