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
Post a Comment