jquery - How do I get Index of Listview? -


i can correct index of listview using code:

$('#listview').on('click', 'li', function() {     alert( $(this).index()); }); 

this returns correct index.

however if using code, returns 0:

$('#listview').on('click', 'div', function() {     alert( $(this).index()); }); 

i use second code differentiate click event among different divs.

the index gives position of element relative siblings in html tree. if div within li , html looks this

<ul id="listview">    <li><div>first div click handler</div></li>    <li><div>second div click handler</div></li> </ul> 

then 0 correct index div in listview. maybe need this

$(this).closest('li').index(); 

in click handler.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -