我的html:
<div class="red-box">
<h2>
<a href="#">My Cars</a>
</h2>
<div class="block_left layout2">
<div class="part1">
<div class="gallery_block">
<div class="block_topic">1</div>
<div class="block_topic">2</div>
<div class="block_topic">3</div>
</div>
</div>
</div>
<div class="red-box">
<h2>
<a href="#">My Bikes</a>
</h2>
<div class="block_left layout2">
<div class="part1">
<div class="gallery_block">
<div class="block_topic">1</div>
<div class="block_topic">2</div>
<div class="block_topic">3</div>
</div>
</div>
</div>
</div>....
<h2><a href="">TITLE</a></h2>
在上面的示例中,有很多具有不同标题的“红框”div 。我只需要选择和更改一个 - “red-box” -> “block_left” -> “part1” -> “gallery_block” -> “block_topic” 其中包含“3”,并且只在单个“red-box”中执行“得到<h2><a href="">My Cars</a></h2>
所以,我正在做以下事情:
if ($(".red-box").children("h2").children("a").children("span:contains('My Cars')").length > 0)
{
// it finds the "red-box" which i need but how to select
// <div class="block_topic">3</div> in the "red-box" whose href has "My Cars"?
}
谢谢