Skip to main content

Bug Tracker

Side navigation

#5873 closed bug (fixed)

Opened January 20, 2010 02:16AM UTC

Closed October 18, 2010 10:11PM UTC

removeClass leaves space after removing last class

Reported by: dmifedorenko Owned by:
Priority: low Milestone: 1.4
Component: core Version: 1.4
Keywords: removeClass space Cc:
Blocked by: Blocking:
Description

Windows XP, Firefox 3.5.7.

Then '.removeClass("disabled")' called for '<tr class="disabled">' the result will be '<tr class=" ">'.

But expected result is '<tr class="">'.

Test case:

<html>

<body>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.js"></script>

Why removeClass add space if here is no class?!

<table>

<tr class="disabled">

<td><h1 onclick="var tr = $(this).parents('tr'); tr.removeClass('disabled'); $('body').append('table row class after removeClass = \\''+tr.attr('class')+'\\'<br/>')">click me</h1></td>

</tr>

</table>

<pre>

To fix: in "removeClass" method after

elem.className = className.substring(1, className.length - 1);

add

if (elem.className == " ") elem.className = "";

</pre>

<br/>

</body>

</html>

Attachments (0)
Change History (5)

Changed February 12, 2010 06:54AM UTC by dmifedorenko comment:1

Hey?! Any body?! Can you fix it? :)

Changed October 06, 2010 03:11AM UTC by addyosmani comment:2

The length of the class once you've removed it does in fact seem to be 1 (ie the space mentioned in the original ticket).

Looking at core, this seems to be being done on purpose in the removeClass function around lines 1297-1282:

var className = (" " + elem.className + " ").replace(rclass, " ");

for ( var c = 0, cl = classNames.length; c < cl; c++ )

{

className = className.replace(" " + classNames[c] + " ", " ");

}

Whilst I think a second review to confirm this behavior's need would be useful, I also question what (if any) impact it being in place has on a developer's ability to modify the class at a later stage as it is just afterall a space.

Live test case: http://jsbin.com/obeji4/2/edit

Flagging for second review.

Changed October 06, 2010 03:11AM UTC by addyosmani comment:3

priority: majorlow

Changed October 18, 2010 12:29PM UTC by paulelliott comment:4

This bug appears to be a duplicate of #5988. It was tested and fixed in the 1.4.2 release.

http://github.com/jquery/jquery/commit/e76ba32cebc26108e15b2e0e03c5152624c1bad9

Changed October 18, 2010 10:11PM UTC by snover comment:5

resolution: → fixed
status: newclosed