0

I'm trying to remove some li lines of html.

This is the html:

HTML

This is the jquery I'm trying to use:

$("li").remove(":contains('undefined')");

Thanks for the help!

1
  • Does the code you tried work? not work? remove too many? It should work. Commented Feb 27, 2013 at 22:49

3 Answers 3

2

You can try:

$("li:contains('undefined')").remove();
Sign up to request clarification or add additional context in comments.

2 Comments

I'm curious why this would work when $("li").remove(":contains('undefined')"); wouldn't. From what I can tell, it looks valid
Weird indeed, however both this and $("li").remove(":contains('undefined')"); actually work for me...
1

I'd do it this way :

$('li').filter(function() {
    return $(this).find('span').text().indexOf('undefined') != -1;
}).remove();

Comments

0

Try:

$("li span:contains('undefined')").remove();

It works in my head :)


EDIT This will remove the LI:

$("li span:contains('undefined')").parent().parent().remove();

3 Comments

this will remove the span, not the li
I tried, but it didn't work for me: $("li span:contains('undefined')").parent().parent().remove();
It worked in jsfiddle - not sure why it's not working in my Rails app. But thanks, I'll work on it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.