javascript - Populating ul list with index -


i having trouble populating ul li index value.

my html below.

<ul>     <li></li>     <li></li>     <li></li>     <li></li> </ul> 

my js below.

$('document').ready(function(){ var indexus = $('li').index(); $('li').each(function(){ $('li').html(indexus); }); }); 

js fiddle: http://jsfiddle.net/kujwc/407/

i want populate li appropriate li index value, can end getting index value of latest (in case 3). how go looping in each index value each li shows value of own index number?

you should this:

$('li').each(function(){     $(this).html($(this).index()); }); 

you adding index li.. istead of $(this) inside of each, using $('li'). adds last value li index of them.


Comments

Popular posts from this blog

ios - Memory not freeing up after popping viewcontroller using ARC -

Java JSoup error fetching URL -

webstorm - PhpStorm file cache conflict with TypeScript compiler -