在jQuery中,如何仅引用子项h2等于“Recipe Test 2”的元素?
<li class="sfnewsListItem">
<h2 class="sfnewsTitle">
<a href="#">Recipe Test 1</a>
</h2>
<div class="sfnewsMetaInfo">May 23, 2011</div>
</li>
<li class="sfnewsListItem">
<h2 class="sfnewsTitle">
<a href="#">Recipe Test 2</a>
</h2>
<div class="sfnewsMetaInfo">May 23, 2011</div>
</li>
<li class="sfnewsListItem">
<h2 class="sfnewsTitle">
<a href="#">Recipe Test 3</a>
</h2>
<div class="sfnewsMetaInfo">May 23, 2011</div>
</li>
答案 0 :(得分:2)
答案 1 :(得分:2)
试试这个:
var parnt =$("h2:contains('Recipe Test 2')").closest("li");