2016-07-31 1 views
0

내부의 특정 요소를 가져옵니다 "image_small_2.jpg는"나는 "image_big_2.jpg"내가 DIV (표시 없음) 내부에 특정 IMG을 얻을 수있는 문제가 생겼어요 숨기기

을 얻을 필요하지만 "image_small_1.jpg"또는 두 번째 이미지를 클릭하면 - 그것은 마지막 "image_big_..n.jpg"를 보여줍니다.

는 또한 jQuery를에 IMG 얻을려고 :

$(function(){ 
    $(".showhide").on("click", function(){ 
    $(".content").css("display","block"); 
    }); 
}); 

그 중 하나가 작동하지 않습니다. 당신이 a의 두 가지 유형에 대한 이벤트 처리기를 부착, jQuery를에 그런

<a title="show" class="showhide">show<img src="image_small_1.jpg" /></a> 
<div class="content"><img src="image_big_1.jpg" /> 
    <a class="hide"><img class="close" src="x.png" alt="x">close</a> 
</div> 
<a title="show" class="showhide">show<img src="image_small_2.jpg" /></a> 
<div class="content"><img src="image_big_2.jpg" /> 
    <a class="hide"><img class="close" src="x.png" alt="x">close</a> 
</div> 
<a title="show" class="showhide"><img src="image_small_..n.jpg" /></a> 
<div class="content"><img src="image_big_..n.jpg" /> 
    <a class="hide"><img class="close" src="x.png" alt="x"></a> 
</div> 

을 :

답변

0

hide처럼, 당신의 내면 a 또한 별개의 클래스를주고, 그들 모두에 onclick 특성을 제거 :

$('a.showhide').click(function(){ 
    $(this).nextAll('.content:first').toggle(); 
}); 

$('a.hide').click(function(){ 
    $(this).closest('.content').toggle(); 
}); 
+0

대단히 감사합니다. 대단 하네! – 3113