Is there anyway to add same animation to every element of same class instead of specifying for individual elements ? | SoloLearn: Learn to code for FREE!

+2

Is there anyway to add same animation to every element of same class instead of specifying for individual elements ?

So can it be a.style just ,instead of a[0] and a[1]? https://code.sololearn.com/WPHClrkufJ3o/?ref=app

6/4/2020 10:36:18 PM

Abhay

4 Answers

New Answer

+3

QuerySelectorAll() returns an array, so you can literally use any array methods on them, for example a.forEach(element => { //a.animate }); You can also add control statement maybe to prevent elements at odd index to be animated a.forEach((element, index) => { if(index & 1) continue; a.animate() }); The looks simple

+3

Mirielle ty

+1

Mirielle, QuerySelectorAll() returns a nodelist object, and while it does have a forEach method, it is not an array. You will have to convert the nodelist to an array to use the other array methods. https://developer.mozilla.org/en-US/docs/Web/API/NodeList.

+1

ODLNT Ok 👌