Javascript - Delegate click event and detect the position of child element(compare with first-child) -
<div class="parent"> <div class="child"></div> <div class="child"></div> <div class="child"></div> <div class="child"></div> <div class="child"></div> </div>
i find appropriate way using javascript when click on 1 of child
element. figure out element's position(not coordinate
) such element third children of parent
element. asking same detect child node number
<script> $(document).ready(function () { $('.child').click(function () { alert("position is" + ($(this).index() + 1)) }); }); </script> <div class="parent" > <div class="child">1</div> <div class="child">2</div> <div class="child">3</div> <div class="child">4</div> <div class="child">5</div> </div>
Comments
Post a Comment