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

Qt4: how to send QString inside a struct via QSharedMemory -

node.js - NodeJS remote terminal to Dropbear OpenWRT-Server -

python - jinja2: TemplateSyntaxError: expected token ',', got 'string' -