Answer the question
In order to leave comments, you need to log in
How to make alternate appearance of words in a row of text?
How to make text appear one by one in a row inside the h1 tag?
Here is the markup:
<div class="header-page">
<h1>раз два три</h1>
</div>
// JavaScript
let strTitle = $(' h1').text();
for(let key of strTitle.split('" ")){
$('.banner-text h1').text(key);
}
Answer the question
In order to leave comments, you need to log in
You will need a reference to the element, and an array of words.
Keep the counter in the variable, it will determine the word from the set.
Will increase by 1 at each step. To get a valid index of an array element from it, take the remainder of the division %
by the length of the array.
There are several things going on here:words[current++ % words.length]
current++
the counter increases by 1, but its value BEFORE the increase comes into operationcurrent % words.length
gives the remainder after dividing by the length of the array. If there are 3 elements in the array, the remainder will be 0, 1 or 2. Just the indices of the words in the array.Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question