jQuery removeClass()不删除所有类 [英] jquery removeClass() not removing all classes

查看:75
本文介绍了jQuery removeClass()不删除所有类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的元素:

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();

我明白了:

[<div id=​"waterhorse" class=​"one two three">​horse​</div>​]

换句话说,它行不通;它不会删除元素上的任何类.不幸的是,我无法在jsfiddle中复制它.

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?

推荐答案

似乎这是jQuery和jQueryUI不能很好地配合使用的已知问题:

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

jQuery的奇怪问题.removeClass()没有做任何事情

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

以上答案是使用.removeAttr('class')而不是.removeClass()

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

这篇关于jQuery removeClass()不删除所有类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆