1
자식을 클릭 할 때 상위 색인 번호를 알고 싶습니다. 예를 들어, 각 ul의 자식을 클릭 할 때 3 ul의 div가 있고 부모 색인 번호가 표시되어야합니다. 그것의 부모. 이것을 어떻게 얻을 수 있습니까?부모 클릭 자식 색인을 어떻게 찾을 수 있습니까?
jQuery를 :
HTML$('.opSection').on('click','li',function(){
var num = $(this).parent('ul').index();
alert(num);
//alert(chartData.Indices[$(this).index()][$(this).index()]);
})
: 나는 여러 요소에 대한 이벤트를 처리 할 때 성능을 향상시키기 위해 이벤트 위임을 사용했습니다
<div class="opSection">//parent of all
<dl><dd>
<ul class="selectGroup" title='allIndia' data-select='1'>
<li data-index="123" class="c_on">All India</li> // when i click any of li i need 0
</ul>
<ul class="selectGroup" title='allIndia' data-select='1'>
<li data-index="123" class="c_on">All India</li> // when i click this, i need 1
</ul>
</dd></dl>
</div>
항상 0입니다. UL은 ('.opSection')의 직접적인 아이들이 아니며, 아이들은 없습니다. 아이들 중 하나는 UL – 3gwebtrain
입니다. @ 3gwebtrain : 제 편집 참조. – Matt