用指定的类隐藏最接近的div [英] Hiding the closest div with the specified class
问题描述
我正在研究一个应用程序,它模仿打开,最小化和关闭的桌面样式应用程序窗口。我设法让他们扩大和崩溃,但我无法得到关闭,我不明白为什么。我需要能够通过单击按钮关闭当前div,请参阅代码/例如。
I'm working on an application in which mimics desktop style application windows that open, minimize and close. I've managed to get them to expand and collapse, but I am unable to get the to close, and I can't figure out why. I need to be able to close the current div by clicking a button, see code / eg. below.
<script>
$(document).ready(function () {
$("form.common").first().show();
$(".expand").click(function () {
$(this).parents().next("form.common").show();
})
$(".collapse").click(function () {
$(this).parents().next("form.common").hide();
});
$(".close").click(function () {
$(this).parents().next("div.module").hide();
});
});
</srcipt>
<div id="task_manager" class="module"> <!-- Need the x with class close to hide this div-->
<h3>Task Manager</h3> <!-- This header and below icons are shown when minimized-->
<div class="module_actions">
<span class="icons_small right close">X</span>
<span class="icons_small right collapse">-</span>
<span class="icons_small right expand">+</span>
</div>
<form class="common">
<fieldset>
<legend> Some Titlee/legend>
</fieldset>
</form>
</div>
任何人都可以看到为什么这不是隐藏div吗?
THANKs,
Can anyone see why this is not hiding the div? THanks,
推荐答案
答案在于:
The answer is in the question:
$(".close").click(function () {
$(this).closest("div.module").hide();
});
Demo fiddle
您还应该将您的呼叫更改为 / code>只是
parent()
,所以你只需在DOM树中上升一级
Also you should change your calls to parents()
to just parent()
so you just go up one level in the DOM tree
这篇关于用指定的类隐藏最接近的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!