jQuery JQuery如何查找和删除li元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10255326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JQuery how to find and remove li element
提问by fkaufusi
I'm tryting to use the JQuery to find and remove the <li>
<a href="/arb/node/53/grouping/edit/">Edit group</a>
</li>
with no luck at all.
我正在尝试使用 JQuery 来查找和删除<li>
<a href="/arb/node/53/grouping/edit/">Edit group</a>
</li>
完全没有运气的 。
Could please let me know to achieve this.
请让我知道以实现这一目标。
<ul class="tabs secondary">
<li class="active">
<a href="/arb/node/53/grouping">View</a>
</li>
<li>
<a href="/arb/node/53/grouping/add">Add new Group</a>
</li>
<li>
<a href="/arb/node/53/grouping/edit/">Edit group</a>
</li>
</ul>
I try the following jquery, but it not work.
我尝试了以下 jquery,但它不起作用。
$(".tabs.secondary:contains(\"Edit group\")").remove()
The right solutions should be something that will find the word "Edit group" and remove it <li>
parent.
正确的解决方案应该是能够找到“编辑组”一词并将其删除的方法<li>
。
Thanks
谢谢
Finau
菲诺
回答by stewe
$("li:has('a'):contains('Edit group')").remove();
回答by K Z
If you are using jQuery:
如果您使用的是 jQuery:
$('.tabs li:has(a[href="/arb/node/53/grouping/edit/"])').remove()
to remove it.
删除它。
Edit: since the number in the path is dynamic, you can probably use the following:
编辑:由于路径中的数字是动态的,您可能可以使用以下内容:
$('.tabs li:has(a[href$="/edit/"])').remove()
which will only remove the URL path that ends with /edit/
.
这只会删除以/edit/
.
回答by Lazerblade
$('a').each(function() {
if ($.trim($(this).text()) == 'Edit Group') {
$(this).parent().remove();
}
});
Edited to target text.
编辑为目标文本。
回答by ezakto
Also you can try:
您也可以尝试:
$('li:eq(2)').remove();
$('.tabs li:eq(2)').remove();