I decided to take off my jQuery trainer wheels and try some native JS. It's been...educational.
Anyway, here's what I'm trying to emulate:
$('.select_me').addClass('give_me more_classes');
So far, I've figured out how to select elements and add a single class to them. What I'm having trouble with, is using an array to add multiple classes to an element.
Here's what I've tried:
// Select the element
var div = document.querySelector('.select_me');
// Create an array with the classes to add
var classArray = ['give_me', 'more_classes'];
// Apply the new classes.
div.classList.add('just_a_test', 'okay'); // Works, but not what I want.
div.classList.add.apply(null, classArray); // Uncaught TypeError: Illegal invocation
I suspect I'm using apply() wrong, but I'm not yet knowledgeable enough to know how to use it properly. Could one of you fine folk educate me, or point me in the right direction?
JSFiddle:
https://jsfiddle.net/peg8zrw7/2/