S
S
svilkov872018-03-12 20:16:58
JavaScript
svilkov87, 2018-03-12 20:16:58

Why doesn't increment work?

Good afternoon/evening/night everyone!

The essence of the problem.

Here is a boring code where the increment on line 11 does not work (I left a comment there).

It is understood that when hovering over any element of the list, the date-artibut for all subsequent elements of the list should be assigned. The value in the variable must increase by one in the variable i. But that doesn't happen.

I will be grateful for the answer.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
twobomb, 2018-03-12
@svilkov87

Take out for each. You have each each re-assigns i = 0 var i = 0; // счетчик

V
Vadim, 2018-03-12
@ShVad

$(document).ready(function(){
  var i=0;
  $('ul li').each(function(){
    $(this).attr('data-position', i);
    i++;
    console.log(i);
  });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question