【发布时间】:2017-06-19 16:50:30
【问题描述】:
这是我当前的代码:
$(".close_btn").click(function(e) {
$(".box1").fadeOut(100);
$(".box2").fadeOut(100);
});
如您所见,目前,当您单击 .close_btn 时,.box1 和 .box2 都将被隐藏。现在我想用$(this)和.closest()来隐藏一个框(点击.close_btn的父级,有两个.close_btn)。我的意思是我想要这样的东西:
$(".close_btn").click(function(e) {
$(this).closest(".box1" OR ".box2").fadeOut(100);
});
这样做可能吗?
【问题讨论】:
-
$(this).closest(".box1, .box2")? -
@Karl-AndréGagnon 是的 .. 很棒。谢谢
标签: javascript jquery html jquery-selectors