jQuery .not() 选择器不适用于 class
jQuery .not() selector not working with class
我正在尝试 select body
的所有直系子代,除了那些匹配特定 class.
的子代
无论我使用 .not()
过滤器还是 :not()
select 或者,当我尝试过滤掉的元素仍然是 selection 的一部分时我按 class 名称过滤。但是,如果我尝试根据其 id 将其过滤掉,则效果很好。
以下是 select 代表:
console.log( $( 'body > *' ).not( '.fullscreen, script' ) ); // div.fullscreen is STILL part of the selection
console.log( $( 'body > *' ).not( '#searchWindow, script' ) ); // div.fullscreen is gone, like I wanted
console.log( $( 'body > *:not(.fullscreen, script)' ) ); // div.fullscreen is STILL part of the selection
console.log( $( 'body > *:not(#searchWindow, script)' ) ); // div.fullscreen is gone, like I wanted
为什么class selector在这种情况下没有效果?
这里是jsfiddle of it.
您在 HTML 中拼写 fullscreen
错误。它包含三个 l
。
看这里:
<div id="searchWindow" class="fulllscreen">
我正在尝试 select body
的所有直系子代,除了那些匹配特定 class.
无论我使用 .not()
过滤器还是 :not()
select 或者,当我尝试过滤掉的元素仍然是 selection 的一部分时我按 class 名称过滤。但是,如果我尝试根据其 id 将其过滤掉,则效果很好。
以下是 select 代表:
console.log( $( 'body > *' ).not( '.fullscreen, script' ) ); // div.fullscreen is STILL part of the selection
console.log( $( 'body > *' ).not( '#searchWindow, script' ) ); // div.fullscreen is gone, like I wanted
console.log( $( 'body > *:not(.fullscreen, script)' ) ); // div.fullscreen is STILL part of the selection
console.log( $( 'body > *:not(#searchWindow, script)' ) ); // div.fullscreen is gone, like I wanted
为什么class selector在这种情况下没有效果?
这里是jsfiddle of it.
您在 HTML 中拼写 fullscreen
错误。它包含三个 l
。
看这里:
<div id="searchWindow" class="fulllscreen">