jQuery删除列表项,其中.text()='blabla' [英] jquery remove list item where .text() = 'blabla'

查看:76
本文介绍了jQuery删除列表项,其中.text()='blabla'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下结构

<ul>
 <li><a ...>something</a></li>
 ...
 <li><a ...>blabla</a></li>
<ul>

我需要删除锚文本为blabla的li元素.

I need to remove the li element where the text of the anchor is blabla.

我将如何选择该元素? $(--what selector here--)

How would i go about selecting this element? $(--what selector here--)

还是我需要遍历每个li并将其.text()值与'blabla'进行比较?

or do I need to loop over each li and compare its .text() value to 'blabla'?

推荐答案

如果您要包含包含(子字符串匹配),则

If you want a contains (substring match) then :contains() works:

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

如果您想精确匹配,例如不匹配"blablabla",则可以使用 .filter() :

If you want an exact match, e.g. not matching "blablabla", you can use .filter():

$('li').filter(function() { return $.text([this]) === 'blabla'; }).remove();

这篇关于jQuery删除列表项,其中.text()='blabla'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆