Trying to figure out what I’m doing wrong when trying to put $(this) in a comma separated list, e.g….
This works….
$('#nav').hover(function(){
$('body > :not(.test)).hide();
$('.test').appendTo('body');
)};
But when I add ‘this’ it does NOT work…
$('#nav').hover(function(){
$('body > :not(.test)', this).hide();
$('.test', this).appendTo('body');
)};
I’m trying to say “Don’t hide .test and also don’t hide this”, can you suggest how to modify my code to do this? Many thanks
The second argument to jQuery is a context in which the selector will be searched for. In your case, you’re trying to find a
bodyelement insidethis, which is whatever#navis, and that is unlikely to have abodyelement as a descendant.Also I’m assuming it’s just a typo in the question but your first example won’t work either because you’re missing the closing quote on the
body > :not(.test)selector.Update based on comments
To also exclude
thisfrom a selection you could use thenotmethod instead of the:notselector:I think your second line is attempting to append
.nav-newsandthistobody, in which case you want the opposite of thenotmethod, which isadd: