I'm trying to add multiple css selectors to an element using classList that's inside a function, but keep getting the below error. How do I do this right?
Uncaught DOMException: Failed to execute 'add' on 'DOMTokenList':
The token provided ('padding fonts') contains HTML space characters, which are not valid in tokens.
https://jsfiddle.net/nordy/h84gadst/1/
function addStyle(element,styleName) {
element.classList.add(styleName);
}
var targetElement = document.getElementById("parent-container");
var addStyleElement = document.getElementById("addStyle");
addStyleElement.onclick = function() {
addStyle(targetElement,'padding fonts');
}
div.classList.add("foo", "bar", "baz");notdiv.classList.add("foo bar baz");as you're doing.