jquery - In each next LI inside UL make data-attribute value higher for x value -


i have ul list lis inside. want make in first li data-value="0.3s" in second 0.6 , in third 0.9 , on.... of course javascript or jquery, in html have

  • , using jquery add data-attributes , values

    so result be

    <li data-value=0.3s> - first <li data-value=0.6s> - second <li data-value=0.9s> - third <li data-value=1.2s> - fourth <li data-value=1.5s> - fifth <li data-value=1.8s> - sixth 

    also, possible add add first 4 increase, on fifth reset , startin again.

    result be:

    <li data-value=0.3s> - first <li data-value=0.6s> - second <li data-value=0.9s> - third <li data-value=1.2s> - fourth <li data-value=0.3s> - fifth (reset) <li data-value=0.6s> - sixth 
  • 1)

    var counter = 0; $('ul > li').each( function() {    $(this).attr('data-value', ++counter * 0.3 +'s'); }); 

    2)

    var counter = -1; $('ul > li').each( function() {    $(this).attr('data-value', ( (++counter % 4) + 1) * 0.3 +'s'); }); 

    u want sth this?


    Comments

    Popular posts from this blog

    javascript - AngularJS custom datepicker directive -

    javascript - jQuery date picker - Disable dates after the selection from the first date picker -