jQuery removeClass通配符 [英] jQuery removeClass wildcard

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

问题描述

是否有任何简单的方法可以删除所有匹配的类,例如,

Is there any easy way to remove all classes matching, for example,

color-*

所以如果我有一个元素:

so if I have an element:

<div id="hello" class="color-red color-brown foo bar"></div>

删除后,它会是

after removing, it would be

<div id="hello" class="foo bar"></div>

谢谢!

Thanks!

推荐答案

removeClass 函数接受函数参数,因为 jQuery 1.4

The removeClass function takes a function argument since jQuery 1.4.

$("#hello").removeClass (function (index, className) {
    return (className.match (/(^|\s)color-\S+/g) || []).join(' ');
});

现场示例: http://jsfiddle.net/xa9xS/1409/

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

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