jQuery选择器NOT [英] jQuery selector NOT

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

问题描述

如何选择所有带有ID的元素?

How do i select everything BUT the element with an id?

<div id="test">
<p id="test"></p>
<p></p>
<p></p>
</div>

我希望能够选择第二个和第三个

I want to be able to select the second and third

推荐答案

您不能将两个元素的ID为"test",但是如果代码如下:

You can't have 2 elements with the id "test" but if the code was as follows:

<div id="test">
<p id="test2"></p>
<p></p>
<p></p>
</div>

那么您就可以使用

$("#test p").not("#test2")

$("#test p:not(#test2)")

仅选择其他两个段落.

有关的文档,请参见 http://api.jquery.com/not/ ()方法(第一个选项)或 http://api.jquery.com/not-selector/::not()选择器(第二个选项).

See http://api.jquery.com/not/ for the documentation for the not() method (first option) or http://api.jquery.com/not-selector/ for the :not() selector (second option).

注意:这不会选择一切",而是选择第二和第三段元素.我认为那就是你的意思:)

Note: this won't select "everything" but rather the second and third paragraph elements. I assume that's what you meant :)

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

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