I have three divs with text inside them which I want to fade in and out on a loop. I had it working in jQuery but decided its best to be in pure Javascript:
<div class="container">
<h2 class="quotes">first quote</h2>
<h2 class="quotes">second quote</h2>
<h2 class="quotes">3rd quote</h2>
</div>
I am trying to convert this jquery into pure vanilla Javascript:
var quotes = $(".quotes");
var quoteIndex = -1;
function showNextQuote() {
++quoteIndex;
quotes.eq(quoteIndex % quotes.length)
.fadeIn(2000)
.delay(2000)
.fadeOut(2000, showNextQuote);
}
showNextQuote();
})();
So far I have manage to convert it to this in pure javascript:
let quotes = document.getElementsByClassName("quotes");
let quoteIndex = -1;
function showNextQuote() {
++quoteIndex;
quotes.eq(quoteIndex % quotes.length)
.fadeIn(2000)
.delay(2000)
.fadeOut(2000, showNextQuote);
}
showNextQuote();
})();
I am seeing an error of quotes.eq is not a function and am unsure how to fix this.
Any suggestions much appreciated.
Thanks