特定の要素を取得する必要があります。a
タグをクリックするとトリガーされるイベントがあります。ul
タグが中にあることしか影響できないため、到達できません。選択したい要素のクラスはtarget
。です。明白な答えはを選択するtarget
ことですが、複数のターゲットクラスがあります。私の質問は、必要な要素をどのようにターゲットにするかです。以下はコードです。
<div id="section">
<div id="target">
Here is the div that I want to target. But I can't target it.
</div>
<div>
<ul>
<li></li>
<a>Clicking here triggers the event.</a>
<li></li>
</ul>
</div>
</div>
<script>
$(a).parentsUntil('#section').children(':gt(0)').children(':gt(2)').css('color','red');
</script>