admin管理员组文章数量:1431413
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 () {
$("formmon").first().show();
$(".expand").click(function () {
$(this).parents().next("formmon").show();
})
$(".collapse").click(function () {
$(this).parents().next("formmon").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="mon">
<fieldset>
<legend> Some Titlee/legend>
</fieldset>
</form>
</div>
Can anyone see why this is not hiding the div? THanks,
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.mon").first().show();
$(".expand").click(function () {
$(this).parents().next("form.mon").show();
})
$(".collapse").click(function () {
$(this).parents().next("form.mon").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="mon">
<fieldset>
<legend> Some Titlee/legend>
</fieldset>
</form>
</div>
Can anyone see why this is not hiding the div? THanks,
Share Improve this question asked Sep 21, 2013 at 18:39 MarkMark 4,8738 gold badges57 silver badges93 bronze badges 3-
Do you see any errors in the console? Other wise your code should work. Also by the way use closest(''.module_actions') instead of
parents()
– PSL Commented Sep 21, 2013 at 18:43 - @PSL, there were no console errors but using .closest worked for me, thanks!!! – Mark Commented Sep 21, 2013 at 18:48
- in that case you have more code than what you showed.. That is why parents() did not work for you. – PSL Commented Sep 21, 2013 at 18:50
3 Answers
Reset to default 3The answer is in the question:
$(".close").click(function () {
$(this).closest("div.module").hide();
});
Demo fiddle
Also you should change your calls to parents()
to just parent()
so you just go up one level in the DOM tree
You had a missing <
in <legend> Some Titlee/legend>
, after that it works.
Check here
This should work :
$(".close").click(function () {
$(this).parent().hide();
});
JSFiddle
Doc : parent()
本文标签: javascriptHiding the closest div with the specified classStack Overflow
版权声明:本文标题:javascript - Hiding the closest div with the specified class - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745578164a2664458.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论