2015-01-26 1 views
0

나는이 HTML {{click_event}} 내가 데이터 상태 나 데이터가 요소를 찾을 수 있습니다 때까지 재귀 적으로 검색 할 한 요소 중 하나에 클릭에가져 오기 부모가 반복적으로

<div id="main-container"> 
    <div style="style-here" data-status="active" data-state="loaded"> 
     <div style="style-here"> 
     <div style="style-here" {{click_event}}></div> 
     </div> 
    </div> 
    <div style="style-here" data-status="active" data-state="unloaded"> 
     <div style="style-here"> 
     <div style="style-here" {{click_event}}></div> 
     </div> 
    </div> 
    <div style="style-here" data-status="inactive" data-state="unloaded"> 
    <div style="style-here"> 
     <div style="style-here" {{click_event}}></div> 
     </div> 
    </div> 
</div> 

에게 있습니다 DIV - 최악의 경우에는 이드를 만날 때부터 검색을 중지합니다.

HTML은 다른 JS 파일에서 생성되며 작성 방법을 변경할 수 없습니다. closest 또는 parentjQuery의 방법이 있습니까? data 속성을 검색하는 방법이 있습니까?

감사합니다.

답변

4

재귀에 대한 필요가 없습니다, 당신은 closest()를 사용할 수 있습니다 데이터 (상태)`받았습니다 감사 당신 로리 McCrossan :

$clickedElement.click(function() { 
    var $parent = $(this).closest('[data-status], [data-state], #main-container'); 
}); 
+0

내가 가장 가까운하지만'DIV로했습니다. – Nebunel

관련 문제