Reputation: 373
Given the following code:
<ul>
<li class="parent">
<a href="#link">
<span>Home</span>
</a>
</li>
<li class="parent">
<a href="#link">
<span>Contact</span>
</a>
</li>
<li class="parent">
<a href="#link">
<span>Blog</span>
</a>
</li>
How can I check the value of the SPAN text, and if it equals "Blog," remove the entire LI from the UL?
The jQuery code I've been messing with is getting too complex, and I'm sure there's some kind of nested "find" approach that will help me solve this using minimal code.
Upvotes: 0
Views: 991
Reputation: 4436
$("span").each(function() {
if( $(this).text()=='Blog')
$(this).closest('li.parent').remove();
});
Upvotes: 0
Reputation: 38112
You can do:
$('ul li span').each(function() {
if($.trim($(this).text())=="Blog") {
$(this).closest('li').remove();
}
});
Upvotes: 0