jQuery를 사용하여 DOM을 트래버스하는 데 유용한 리소스가 많이 있지만, 필자의 예에는 운이 좋지 않습니다.jquery로 대체 요소 링크를 클릭하십시오.
내 사이트에 www.smithgrey.co.uk 나는 그들 앞에 '섹션 제목'div가있는 일련의 미리보기 갤러리가 있습니다.
내가 달성하고자하는 것은 'section-title'div를 클릭하면 첫 번째 <a href>
오른쪽에있는 미리보기 이미지의 링크가 클릭됩니다.
class="section-title"
의 인스턴스가 여러 개 있습니다. 불행하게도 ID 또는 클래스를 추가 할 수 없습니다. 이는 동적으로 생성되며 가능하면 그대로 유지해야합니다.
html로는 다음과 같습니다
<body>
<div id="content-grid">
<div class="section-title">
<span class="section-title-type">Title of the first thumbnail gallery</span>
</div>
<div class="index-article">
<a href="#" class="fancybox">
<img src="thumbnail-1">
</a>
</div>
<div class="section-title">
<span class="section-title-type">Title of the second thumbnail gallery</span>
</div>
<div class="index-article">
<a href="#" class="fancybox">
<img src="thumbnail-2">
</a>
</div>
<div class="index-article">
<a href="#" class="fancybox">
<img src="thumbnail-3">
</a>
</div>
<div class="index-article">
<a href="#" class="fancybox">
<img src="thumbnail-4">
</a>
</div>
</div>
</body>
을 그리고 여기에 지금까지 내 jQuery를하지만, 내가 첫 번째 또는 <div class="section-title">
초를 클릭하면이 링크에 상관없이 클릭하기 때문에 그것은 내가 상상 결과를 얻을하지 않습니다 .
$('div.section-title').click(function(){
$(this).parent().next($('div.index-article')).children('a.fancybox').click();
});
솔루션 : 내가 관리하는 다른 commentors의 도움으로
내가 예상대로 작동하게하는 방법을 알아낼 수 :
$(document).ready(function() {
$('div.section-title').click(function(){
$(this).next('.index-article').find('a.fancybox:first').click();
});
});
이봐, 난 당신의 제안에게 이동하지만 행운을했다하지만 난 다음 내용 (바이올린하기 시작했다) 나는 일이있어 - 너무 감사합니다 도움을 청합니다. –