How can I select each and everything on a page except a particular div using jQuery?
Actually I am trying to fade the rest of background on popup of a particular div. But the problem is that not everything is inside some div. Few elements don't have any parent div.
<body>
12345
<div id='second_div'>
XXXXXX
</div>
56789
<div id='popup'>
AAAAA
</div>
</body>
I am using code below but this is not fading content which don't have a parent div(i.e 12345 and 56789). It is only fading content of 'second_div'(i.e. XXXXXX ).
$('body > div:not(#popup)').css("opacity",'0.7');
Please guide me on how to do this using jQuery.
I think you are looking for this:
The reason this works is because it selects all the direct descendants of
body
and then removes all direct descendants that have anid
ofpopup
.Tested it and works perfectly, although I've tested the other one and it doesn't but anyway, good luck!