隐藏除文档某一部分中的一个 div 之外的所有 div
我正在编写一个用户帐户页面,用户可以在其中更改其设置,该页面由用户单击顶部的选项卡组成,页面的内容部分会更新以显示其设置的该部分。
HTML 代码(仅内容部分):
<div id="content_navigation">Navigation menu with buttons, etc...</div>
<div id="pass_settings">
<p>Password settings page</p>
</div>
<div id="email_settings">
<p>Email settings page</p>
</div>
<div id="delete_account">
<p>Delete account page</p>
</div>
我遇到的问题是,我希望绑定到导航菜单中按钮的每个 jQuery 事件都隐藏设置中除特定 div
之外的所有事件。
例如,如果他们单击“密码”按钮,它将隐藏除密码菜单之外的所有内容。
我知道这样的代码:
$('div:not(#myDiv)').hide(); // hide everything that isn't #myDiv
但这适用于文档中的每个 div
。我只希望它在这个特定部分中隐藏除一个之外的所有内容。有没有一种方法可以做到这一点,而无需再放入另一个 div
来包裹它们?
I'm writing a user account page where users can change their settings, and the page consists of tabs at the top where users click, and the content section of the page updates to display that part of their settings.
HTML code (just the content part):
<div id="content_navigation">Navigation menu with buttons, etc...</div>
<div id="pass_settings">
<p>Password settings page</p>
</div>
<div id="email_settings">
<p>Email settings page</p>
</div>
<div id="delete_account">
<p>Delete account page</p>
</div>
The problem I have is that I want each jQuery event that I have bound to a button in the navigation menu to hide all but a specific div
from the settings.
For example, if they click on the "Password" button, it'll hide everything but the password menu.
I know about code like this:
$('div:not(#myDiv)').hide(); // hide everything that isn't #myDiv
but that applies to every div
in the document. I only want it to hide all but one, within this specific section. Is there a way to do this without throwing in yet another div
to wrap around them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
类肯定是为了这个目的而存在的。
HTML:
JS:
Classes surely exist for this purpose.
HTML:
JS: