[英]How to select all elements except the ones with a given class, using jQuery?
[英]Select all html elements except ones with specified class
此代碼將所有html元素與“a”類放在一個名為“items”的數組中。
var items = $('.a').get();
我必須寫些什么才能做相反的事情? 我的意思是,將所有html元素除了.a放入數組中?
下面的代碼和幾個變體不起作用。
var items = !$('.a').get();
$('body *:not(.a)')
要么:
$('body *').not('.a')
如果您還需要在<head></head>
包含這些內容,只需從選擇器中刪除主體即可。
var items = $(':not(.a)').get();
您可以執行以下操作:
$('*').not('.a')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.