mana
mana

Reputation: 1239

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

Upvotes: 4

Views: 41878

Answers (4)

K Z
K Z

Reputation: 30453

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

Upvotes: 7

stewe
stewe

Reputation: 42612

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

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

Upvotes: 10

Lazerblade
Lazerblade

Reputation: 1127

$('a').each(function() {
    if ($.trim($(this).text()) == 'Edit Group') {
        $(this).parent().remove();
    }
});

Edited to target text.

Upvotes: 2

ezakto
ezakto

Reputation: 3194

Also you can try:

$('li:eq(2)').remove();

$('.tabs li:eq(2)').remove();

Upvotes: 2

Related Questions