The correct way to give an element multiple classes is simply put spaces between them. Right?
Then why does the selector [class=CLASSNAME] not work unless it's the only class?
[class^=CLASSNAME] works if the class is the first one.
But how to select all elements that possess a given class, regardless of the number or order of their classes?
I want to select all the elements with class foo-bar. But the code below only selects the first one.
const selector = '[class=foo-bar]';
const divs = document.querySelectorAll(selector);
console.log([...divs].map(div => div.textContent));
<div class="foo-bar">foo</div>
<div class="foo-bar baz">bar</div>
<div class="baz foo-bar">baz</div>