2013-05-13 5 views
1

아래 코드는 제 코드입니다. 내 목표는 사용자가 '형제 2'에있는 <a> 태그를 클릭 할 때입니다. '형제'콘텐츠에있는 '안녕하세요'에게 알려 드리고 싶습니다. 이것을 어떻게 할 수 있습니까?부모님 형제 콘텐츠를 얻는 방법 Jquery

<div class="parent"> 
    <div class="sibling_1"> 
     <div class="selections"> 
      <p>Hello</p> 
      <p>How Are You?</p> 
     </div> 
    </div> 

    <div class="sibling_2"> 
     <a href="">Click Me!</a> 
    </div> 
</div> 

답변

1

편도 내가 시도 S :

$("div.sibling_2 a").click(function(e) { 
    e.preventDefault(); 
    var text = $(this).parent().prev().find("div.selections p:eq(0)").text(); 
    alert(text); 
}) 

Demo

1

다음 작품

$('a').on('click', function(){ 
    alert($(this).closest('.parent').find('p:first-child').text()); 
    return false; 
}) 

http://jsbin.com/uvevek/3/edit

1

$(function() { 
    $('.sibling_2 a').click(function(e) { 
     e.preventDefault(); 
     alert($('.sibling_1').text()); 
    }); 
}); 
당신은 그것을 달성하기 위해 여러 가지 방법이

http://jsfiddle.net/tamilcselvan/p9mEx/