选择没有任何类的元素 [英] Select elements without any class
问题描述
我需要通过jQuery选择器找到页面中没有类的所有跨度。
$ b 示例:
< span class ='Cool'>找不到我< / span>
< span>我,我,请带我!!!< / span>
使用 :not()
和属性不选择 [att!= val]
来过滤掉非-empty class
属性:
$('span:not([ class!=])')
注意然而该 [ATT!= VAL]
是一个非标准的jQuery选择器,这意味着选择器不能用于CSS或 document.querySelectorAll()
。如果你和我一样,并且你是遵守标准的人,并且希望在可能的情况下避开非标准的jQuery选择器,下面是一个直接的等价物:
< pre $
$('span:not([class]),span [class =]')
匹配
-
span
元素有 noclass
属性和 -
span $ c $ 的
元素具有 类
属性,但仅当属性值为空时
然而,在大多数情况下,您应该能够避开第一部分:
$('span:not([class])')
通常只在负责输出它的应用程序生成的标记中找到空的类
属性,或者由不注意的开发者找到。
I need to find, via jQuery selectors, all spans in a page that have no class.
Example:
<span class='Cool'>do not found me</span>
<span>me, me, take me please!!!</span>
Use :not()
and the attribute not selector [att!=val]
to filter out elements with a non-empty class
attribute:
$('span:not([class!=""])')
Note however that [att!=val]
is a non-standard jQuery selector, which means the selector cannot be used in CSS or with document.querySelectorAll()
. If you're like me, and you're a stickler for following the standards and so want to eschew non-standard jQuery selectors where possible, the following is a direct equivalent:
$('span:not([class]), span[class=""]')
This matches
span
elements that have noclass
attribute, andspan
elements that do have aclass
attribute, but only when the attribute value is empty.
In most cases, though, you should be able to get away with just the first portion:
$('span:not([class])')
You'll usually only find empty class
attributes in markup generated by the application that's responsible for outputting it, or by developers who aren't paying attention.
这篇关于选择没有任何类的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!