开发者

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜