Reputation: 393
I'm dynamically adding list items to a ul
<ul>
<li>thing 1</li>
<li>thing 2</li>
<li class='colorblock'>thing 3</li>
<li class='colorblock'>thing 4</li>
<li>thing 5</li>
</ul>
In some situations I need to enclose a few of the li with the following
$('.colorblock:first').before('<li>[± </li>');
$('.colorblock:last').append('<li>]</li>');
that products the following
<ul>
<li>thing 1</li>
<li>thing 2</li>
<li>[± </li>
<li class='colorblock'>thing 3</li>
<li class='colorblock'>thing 4</li>
<li>]</li>
<li>thing 5</li>
</ul>
now, if I also may need to remove those two li's with something along the following
$('li').filter(function() { return $.text([this]) === '[± '; }).remove();
$('li').filter(function() { return $.text([this]) === '[± '; }).remove();
$('li').filter(function() { return $.text([this]) === ']'; }).remove();
my problem is that none of these are correctly matching to
<li>[± </li>
I've ran out of ideas on how to strictly match and remove that li. any suggestions?
Upvotes: 0
Views: 51
Reputation: 393
Turns out it was an encoding issue with the file it was in, needed to be UTF-8
Upvotes: 0
Reputation: 388326
Try
$('li').filter(function(){
var txt = $.trim($(this).text());
return txt == '[±' || txt == ']'
}).remove()
Demo: Fiddle
Upvotes: 1