css中:not()选择器和jQuery中.not()方法

文章2019-07-13879 人已阅来源:网络

因为老是将这两个的not方法弄混,所以写一下备忘。

css中:not()选择器用法

:not 伪类选择器可以筛选不符合表达式的元素,:not(selector) 其中的selector为css选择器

ul li:not(:first-child)
ul li:not(.text) //不包含class="text"的元素
:not(p) //非段落元素
ul li:not(:first-child):not(:last-child)  //not可叠加使用

jQuery中.not()方法

not() 从匹配元素集合中删除元素。

$("p").not("#selected")  //选择id!=selected的段落元素
$('li').not(':even').css('background-color', 'red');  //选择不是偶数的li元素

选择class!=test的input元素的两种方法

$(input:not(.test)).css(...);
$(input).not(".test").css(...)