2012-04-16 6 views
4

나는 다음과 같은 HTML 마크 업이 있습니다jQuery를 쇼 다음 부모 DIV

<div id="step1" class="step"> 
        <h1>Enter code</h1> 
        <p><input type="text" value="<%= @groupCode %>" name="group_code" class="span3" /> 
         <a class="btn btn-primary btn-medium"> 
          Next &raquo; 
         </a> 
        </p> 
       </div> 
       <div id="step2" class="step" style="display: none"> 
        <p>Hello World</p> 
       </div> 

링크 (.btn) 나는 다음 부모 DIV (#step2)을 보여주기 위해 필요하고을 클릭하면 있습니다. 이 과정을 등록 과정으로 설계 했으므로 여러 부모 항목 div (모두 {{id}로 이름이 지어 짐)

어떤 도움을 주실 수 있나요?

답변

8

당신은 같은 것을 사용할 수 있어야합니다 : 현재 하나를 숨기고 약간의 페이딩 효과 다음 중 하나를 표시 할 경우

//This should access the parent (step1), then the next element (step2) 
$(this).parent().next() 
+0

빠른 답장을 보내 주셔서 감사합니다! 나는 당신의 코멘트를 보았을 때 실제로 그것을 실제로 알아 냈습니다. 웃음! 나는 $ (this) parent ('. step')와 비슷한 것을했다. next()' – dennismonsewicz

+0

다행이다. 부모 영역 내에서 추가 선택기를 사용하는 것에 대해 막 언급하려고했습니다. –

2
jQuery('.btn').click(function(){ 
    jQuery(this).closest('.step').next().show(); 
}); 
2
$(function(){ 
    $(".step a.btn").click(function(){ 
    var item= $(this); 
    item.parent().parent().next().show(); 
    }); 
}); 

,이

을 수행 할 수 있습니다
$(function(){ 
    $(".step a.btn").click(function(){ 
    var item= $(this); 
     item.parent().parent().fadeOut(400,function(){ 
     item.parent().parent().next(".step").fadeIn(300); 
     }); 
    }); 
}); 

다음은 예입니다. http://jsfiddle.net/Jm7fW/15/