通过内容查找html元素并使用jQuery隐藏

fig*_*r20 4 jquery find hide

我正在尝试使用jquery在某些HTML中查找某些元素,我想查找和隐藏包含标签文本“ This is my test label”和“ Yest another test label”的列表ID。

<ul id="mylist" class="top_level_list">
<li id="field66" class="myfield">
    <div class="field_icons">
        <div class="title">This is my title</div>
    </div>
    <label class="my_label" for="input71">This is my test label</label>
</li>
<li id="field20" class="myfield">
    <div class="field_icons">
        <div class="title">This another test title</div>
    </div>
    <label class="my_label" for="input71">Yet another test label</label>
</li>
Run Code Online (Sandbox Code Playgroud)

我已经找到了jQuery .hide函数以及.find()函数,但是我不确定如何使用其中的内容选择元素。

有人可以帮忙吗?

Tim*_*son 5

这是一个稍微简单的解决方案。$(".my_label:contains('This is my test label')").hide();。您可以在此处查看其运行情况:http : //jsfiddle.net/kPxTw/