在jQuery中获取具有特定内部HTML值的所有链接 [英] Getting all links with specific inner HTML value in jQuery

查看:81
本文介绍了在jQuery中获取具有特定内部HTML值的所有链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<div>
    <a>
       Text1
       <img alt="" stc="" />
    </a>
    <a>
       Text2
    </a>
 </div>

我想选择所有具有text=text2的锚元素.我正在寻找这样的东西:

I want to select all anchor elements that have text=text2. I'm looking for something like this:

$('a[text=Text2]')


编辑:为什么这不起作用?由于某些原因,它必须采用以下格式:


Why this is not working? For some some reason, it needs to be in this format:

$('div').find('a').find(':contains("Text2")')

推荐答案

您问为什么这不起作用:

You ask why this doesn't work:

$('div').find('a').find(':contains("Text2")')

原因是, .find() 将搜索子元素,您需要

The reason is, .find() will search children elements, you want .filter() (because you already selected the a - or you add the :contains to the a find:

$('div').find('a').filter(':contains("Text2")');
$('div').find('a:contains("Text2")');

这篇关于在jQuery中获取具有特定内部HTML值的所有链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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