jQuery:仅当元素没有类名时才选择它 [英] jQuery: Select an element only when it has no class name

查看:88
本文介绍了jQuery:仅当元素没有类名时才选择它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅当元素没有任何类时,如何才能使用jQuery选择元素?

How can I use jQuery to select an element only if it doesn't have any classes?

我正在编写一个页面,该页面允许html作者通过向该元素添加一个类来覆盖默认的jQuery操作.完全可以是任何班级.

I'm writing a page which allows the html author to override the default jQuery action by adding a class to the element. It should be any class at all.

因此标记可能是:

<ul>
  <li class="override"></li>
  <li></li>
</ul>

我希望jQuery只选择第二个列表元素,因为它没有类.

I'd like jQuery to only select the second list element because it doesn't have a class.

我已经看过.hasClass(),但是它似乎需要一个特定的类名.

I've looked at .hasClass(), but it seems to require a specific class name.

谢谢!

推荐答案

:not()选择器– jQuery API

$('li:not([class])')

这篇关于jQuery:仅当元素没有类名时才选择它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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