Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery how to find and remove li element

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.

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.

$(".tabs.secondary:contains(\"Edit group\")").remove()

The right solutions should be something that will find the word "Edit group" and remove it <li> parent.

Thanks

Finau

like image 220
mana Avatar asked Nov 29 '22 14:11

mana


2 Answers

$("li:has('a'):contains('Edit group')").remove();

Demo: http://jsfiddle.net/YqFfe/

like image 143
stewe Avatar answered Dec 02 '22 05:12

stewe


If you are using jQuery:

$('.tabs li:has(a[href="/arb/node/53/grouping/edit/"])').remove()

to remove it.

jsfiddle

reference

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/.

new jsfiddle

like image 31
K Z Avatar answered Dec 02 '22 03:12

K Z