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

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

问题描述

我正在尝试使用jquery在某些HTML中查找某些元素,我想查找并隐藏包含标签文本"This is my test label"和"Yest another test label"的列表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('This is my test label')").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天全站免登陆