我試圖選擇所有不是'選擇器'的元素。
類似
var $removable = $container.find(.not(selector));
但我知道語法是錯誤的。 任何人都可以幫忙嗎? 感謝
我試圖選擇所有不是'選擇器'的元素。
類似
var $removable = $container.find(.not(selector));
但我知道語法是錯誤的。 任何人都可以幫忙嗎? 感謝
你可以試試這個:
var $removable = $container.find(':not('+ selector +')');
OR
var $removable = $container.find('some_selector').not(selector);
$container.find('some_selector:not('+selector+')'
我建議使用第二個例子,因爲第一個例子可能需要挖掘'$ container'的所有*後裔。您希望'some_selector'具有足夠的限制性,所以需要執行'.not()'子句的集合相對較小。請注意,第二個示例等同於'$ container.find('some_selector:not('+ selector +')')',但後者僅使用一個DOM查詢而不是兩個。 – 2012-07-31 14:06:04
非常感謝。 – 2012-07-31 22:58:13
這是簡單的使用沒有選擇器
$('div').not('#selector').css('background-color', 'red');
看到這個live example。上面的例子假設你想要找到不是id爲'selector'的元素的div元素。
http://api.jquery.com/category/selectors/ :) – NicoSantangelo 2012-07-31 14:02:13