我可以 Select (使用jQuery)HTML标记中的所有div,如下所示:
$('div')
但是我想从上面的 Select 中排除一个特定的div
(比方说有id="myid"
).
How can I do this using Jquery functions?
我可以 Select (使用jQuery)HTML标记中的所有div,如下所示:
$('div')
但是我想从上面的 Select 中排除一个特定的div
(比方说有id="myid"
).
How can I do this using Jquery functions?
Simple:
$('div').not('#myid');
Using .not()
will remove elements matched by the selector given to it from the set returned by $('div')
.
您还可以使用:not()
Select 器:
$('div:not(#myid)');
然而,这两个 Select 器做的是相同的事情,不过是:not()
is faster,大概是因为jQuery的 Select 器引擎Sizzle可以将其优化为本机.querySelectorAll()
调用.