jQuery是否选择除特定id下的元素之外的所有元素?
基本上,我希望避免突出显示id“子菜单”下的任何内容。现在它似乎忽略了not选择器。首先,您的选择器缺少一个空格jQuery是否选择除特定id下的元素之外的所有元素?,jquery,Jquery,基本上,我希望避免突出显示id“子菜单”下的任何内容。现在它似乎忽略了not选择器。首先,您的选择器缺少一个空格 $('body *').not("#submenu*").mouseover(function(e){ e.stopPropagation(); $(this).addClass('highlight'); }); $('body *').not("#submenu *").mouseout(function(e){ e.stopPropagation();
$('body *').not("#submenu*").mouseover(function(e){
e.stopPropagation();
$(this).addClass('highlight');
});
$('body *').not("#submenu *").mouseout(function(e){
e.stopPropagation();
$(this).removeClass('highlight');
});
演示:使用
*
表示需要所有元素。因为您在它前面加了#子菜单
,所以它会找到#子菜单
中的所有元素。
$('body *').not("#submenu *").mouseover(function(e){
e.stopPropagation();
$(this).addClass('highlight');
});
$('body *').not("#submenu *").mouseout(function(e){
e.stopPropagation();
$(this).removeClass('highlight');
});