删除更高层 [英] Removing higher layer
本文介绍了删除更高层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想删除第8层比这层更高。
I want to remove 8th layer upper than this layer.
所以我写了这段代码: http://jsfiddle.net/3JaGg/
此代码现在正常工作,但我想知道有更好的方法吗?
so I wrote this code : http://jsfiddle.net/3JaGg/ this code work now, but I want to know is there any better way ?
因为我使用 parent()
8次。
$(this).parent().parent().parent().parent().parent().parent().parent().parent().remove();
注意:我使用了很多DIV,因为我想用CSS2对角进行四舍五入
Note: I use many DIVs because I want rounding the corners with CSS2
推荐答案
使用 nearest()
,这将遍历DOM以找到带有选择器的最近元素您提供 - 在您的情况下,最近(。弹出)
将起作用。
Use closest()
, this will traverse up the DOM to find the nearest element with the selector you provide - in your case, closest(".popup")
will work.
$('.closeBtn').click(function() {
$(this).closest(".popup").remove();
});
这篇关于删除更高层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文