How to change var in js?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
29 views
$('.calk-section__btns .link-next').click(function(){ var spanStage = '.calk-section__span stages' if($(spanStage).hasClass('active')){ var valStage = 1 valStage = ++valStage var newsStage = '.calk-section__stages span[name='+valStage+']' console.log(valStage+' '+newsStage) $(spanStage).removeClass('active') $(newsStage).addClass('active') } })


// want the next time you click the value valStage was 1 more
by | 29 views

1 Answer

0 like 0 dislike
Now you make with every click var valStage = 1
Take it in the first place.
var valStage = 0 // initially 0, when you click will increase the same $('.calk-section__btns .link-next').click(function(){ var spanStage = '.calk-section__span stages' if($(spanStage).hasClass('active')){ /* remove this var valStage = 1 valStage = ++valStage instead write: */ valStage++ var newsStage = '.calk-section__stages span[name='+valStage+']' console.log(valStage+' '+newsStage) $(spanStage).removeClass('active') $(newsStage).addClass('active') } })
by
110,608 questions
257,187 answers
0 comments
40,796 users