How to remove an html element according to its contents with jquery?
If I have some html like this.
<ul class="menu">
<li>
<a href="pageGreen">
pageGreen
</a>
</li>
<li>
<a href="pageBlue">
pageBlue
</a>
</li>
<li>
<a href=开发者_开发百科"pageRed">
pageRed
</a>
</li>
<li>
<a href="page1">
page1
</a>
</li>
<li>
<a href="page2">
page2
</a>
</li>
<li>
<a href="page3">
page3
</a>
</li>
</ul>
How would I remove the entire LI element for pageGreen and pageBlue only, using jquery?
something like this could work
$("a[href='pageGreen']").parent().remove();
You could try something like....
$("li a").each(function() {
if($this).html() == "pageGreen" || $(this).html() == "pageBlue") {
$(this).closest("li").fadeOut();
}
});
Might need tweaking
Try jQuery’s :contains()
selector:
$("li:contains(pageGreen), li:contains(pageBlue)").remove();
精彩评论