E
E
Evgeny Karpov2018-02-11 00:44:34
JavaScript
Evgeny Karpov, 2018-02-11 00:44:34

How to implement an infinite increase in numbers on the site in several blocks with one class?

How to make a number increase by 1 or any other, to infinity? the problem is that this needs to be done on the same page of the site for several blocks with a common class. The input and output values ​​must be different. Those. starting number, say, for 4 blocks 100, 240, 50, 345 from them, each counter with its own block and starts counting.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2018-02-11
@ewal

let blocks = document.querySelectorAll('.foo')
setInterval(function(){
  blocks.forEach(block => {
  	block.textContent = +block.textContent + 1
  })
}, 500)
https://jsfiddle.net/32jufnm8/
Same with jQuery
let blocks = $('.foo')
setInterval(function(){
  blocks.each(function(){
  	this.textContent = +this.textContent + 1
  })
}, 500)
https://jsfiddle.net/32jufnm8/1/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question