jQuery的 - 选择页面上的所有内容除了一格 [英] jQuery - Select everything on a page except one div

查看:178
本文介绍了jQuery的 - 选择页面上的所有内容除了一格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何选择每一切页面上除了使用jQuery一个特定的div?

How can I select each and everything on a page except a particular div using jQuery?

其实我试图淡化背景的其余部分在特定的div的弹出窗口。
但问题是,并非一切都是一些DIV中。 几个要素不具有任何父DIV。

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>

我使用低于code但这不褪色不具有父内容的div (即12345和56789)。它只是褪色second_div'(即。XXXXXX)的内容。

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');

请指导我如何做到这一点使用jQuery。

Please guide me on how to do this using jQuery.

推荐答案

我认为你正在寻找这样的:

I think you are looking for this:

$("body > *").not('#popup').css("opacity", '0.7');

这部作品的原因是因为它选择所有的直系后裔,然后删除该有一个 ID的所有直系后裔 弹出的

The reason this works is because it selects all the direct descendants of body and then removes all direct descendants that have an id of popup.

这篇关于jQuery的 - 选择页面上的所有内容除了一格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆