jquery – 查找子项目h2文本具有特定值的元素

我觉得这很简单,但我似乎找不到正确的选择器语法.我有这样的 HTML
<div class="parent">
    <h2>Summary</h2>
    <p>... bunch of content ...</p>
</div>
<div class="parent">
    <h2>Statistics</h2>
    <p>... bunch of content ...</p>
</div>
<div class="parent">
    <h2>Outcome</h2>
    <p>... bunch of content ...</p>
</div>

我想找到其h2小孩包含文本“统计”的div.

我尝试过各种组合:

$(".parent").find("h2[text='Statistics'").parent()

这不起作用,因为find返回一个空集.如果我这样做:

$(".parent").find("h2").text("Statistics").parent()

我收回了3个元素 – 所有这些元素都是包含统计信息的div.我可以先添加一个(),但是似乎有点粗.什么是正确的语法来找到一个项目?

解决方法

使用:
$(".parent").find("h2:contains('Statistics')").parent();

这使用:contains()选择器.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...