I wanna create some loading dots, like this:
At 0000 miliseconds the span content is: .
At 0100 miliseconds the span content is: ..
With String.prototype.repeat()
you can do:
var element = document.querySelector(...);
var counter = 0;
var intervalId = window.setInterval(function() {
counter += 1
element.innerHTML = '.'.repeat(1 + counter % 3)
}, 350);
// Use the following to clear the interval
window.clearInterval(intervalId)
Note: String.prototype.repeat()
is currently not supported in < IE11