如何删除父元素? [英] How do I remove the parent element?
本文介绍了如何删除父元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是jquery的新手,甚至不确定我是否正确引用了"parent"元素.我想完全删除两个<li>
标记.有没有一种方法可以只用一个id声明呢?
I'm brand new to jquery and am not even sure if I'm referring correctly to the "parent" element. I want to remove the two <li>
tags completely. Is there a way to do this with only a single id declaration?
<li class="remove"><a href="#">ds</a></li>
<li class="remove"><a href="#">xfg</a></li>
<li><a href="#">ds</a></li> <------This stays as well as the one below
<li><a href="#">xfg</a></li>
推荐答案
您可以
$('.remove').remove(); // all which matches a class="remove" will be gone completely.
或单击它的<a>
$('#ulID li a').click(function(){
$(this).closest('.remove').remove();
return false; // prevent link to jump to a page.
});
欢迎使用 stackoverflow.com
别忘了接受答案
Welcome to stackoverflow.com
Don't forget to accept an answer
这篇关于如何删除父元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文