jquery removeClass() not removing all classes

javascript, jquery

Solution

Seems like this is a known problem with jQuery and jQueryUI not playing nicely together:

Odd issue with jQuery .removeClass() not doing anything

http://bugs.jqueryui.com/ticket/9015

The answer above is a workaround that uses `.removeAttr('class')` instead of `.removeClass()`

Problem

I have an element like this: ``` <div class="one two three" id="waterhorse">horse</div> ``` When I run this code in the browser console: ``` $("#waterhorse").removeClass(); ``` I get this: ``` [<div id=​"waterhorse" class=​"one two three">​horse​</div>​] ``` In other words, it doesn't work; it doesn't remove any classes on the element. I unfortunately can't reproduce it in jsfiddle. However, I can remove a specific class: ``` $("#waterhorse").removeClass("two"); ``` Also, this will remove all classes: ``` $("#waterhorse").removeAttr("class"); ``` Any idea why the latter works to remove all classes, but the former doesn't?

Original source

Related problems