我需要选择父div而不是child,我该如何在jQuery中做到这一点。 基本上我想创建一个简单的登录框,它应该隐藏当且仅当我点击父div时,如果我点击子div不应该隐藏。
以下是代码。jquery select parent not child
jQuery(document).ready(function()
{
jQuery("li.login-link").click(function()
{
jQuery("div#login-container").css("display", "block");
});
jQuery("div#login-container not:(div#login-box)").click(function()
{
jQuery("div#login-container").css("display", "none");
});
});
<div id="login-container"> <!--parent div. Should hide when i click on this div-->
<div id="login-box"> <!--child div. Should not hide parent when i click on this-->
</div>
</div>
对不起你什么意思?因为你有一个ID ......用它来选择元素 –
我的要求是,当我点击的div#登录容器它会(#登录框) –