按内容查找html元素并使用jQuery隐藏 [英] Find html element by content and hide using jQuery

查看:21
本文介绍了按内容查找html元素并使用jQuery隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 jquery 在某些 HTML 中查找一些元素,我想查找并隐藏包含标签文本这是我的测试标签"和是另一个测试标签"的列表 ID

I am trying to use jquery to find some elements in some HTML, I would like to find and hide the list id that contains the label text 'This is my test label' and 'Yest another test label

<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>

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

I have found the jQuery .hide function as well as the .find() function but i'm unsure as to how to select the element using the content within it.

谁能帮忙?

推荐答案

这是一个稍微简单的解决方案.$(".my_label:contains('这是我的测试标签')").hide();.你可以在这里看到它的实际效果:http://jsfiddle.net/kPxTw/

This is a slightly easier solution. $(".my_label:contains('This is my test label')").hide();. You can see it in action here: http://jsfiddle.net/kPxTw/

这篇关于按内容查找html元素并使用jQuery隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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