私の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 がたくさんあります。そして、「3」を含む「red-box」->「block_left」->「part1」->「gallery_block」->「block_topic」を1つだけ選択して変更する必要があり、単一の「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"?
}
ありがとう