Help please concisely initialize the script for the elements of the rainbow_text class.

As you can see, now I have initialization for 3 elements with handles. This is not rational since there may be much more.

It would be great not to use loops.

html:

 <span>header</span> <br /> <div class="logo"> weterteyrtutyu<span class="rainbow_text" >sergey kalinin 123</span>wqeqweqwqrvdg </div> <br /> <span class="rainbow_text" >qwerty asdf zxzx</span> <br /> <span>footer</span> <br /> <span class="rainbow_text" >qzx</span> 

js:

  new KalininRainbowText({ element: document.getElementsByClassName ('rainbow_text')[0], colorArray: new Array('red', 'lime', 'blue', 'navy', 'green', 'magenta', '#883f46', '#4bb1ff') }); new KalininRainbowText({ element: document.getElementsByClassName ('rainbow_text')[1], colorArray: new Array('red', 'lime', 'blue', 'navy', 'green', 'magenta', '#883f46', '#4bb1ff') }); new KalininRainbowText({ element: document.getElementsByClassName ('rainbow_text')[2], colorArray: new Array('red', 'lime', 'blue', 'navy', 'green', 'magenta', '#883f46', '#4bb1ff') }); 
  • It would be logical to show the fiddle, as I understand KalininRainbowText is your own object, and why it does not work simply with a NodeList - the question is entirely yours. - zb '
  • yes i am sorry here is the fiddle jsfiddle.net/yrUJy >> why it doesn’t work just with NodeList I would like to try out this method for training - cyklop77

1 answer 1

If I understand correctly what you want to do.

 var elements = document.getElementsByClassName('rainbow_text'); var colorArray = ['red', 'lime', 'blue', 'navy', 'green', 'magenta', '#883f46', '#4bb1ff']; for (var i = 0; i < elements.length; i++) { new KalininRainbowText({element: elements[i], colorArray: colorArray}); }