Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter objects by className from nodeList

I've got a nodelist of objects returned by a call to document.getElementsByClassName('a'). Some of these objects have an extra class b. How can I create an array of elements that contain both classes? I don't was use a global search for b. I prefer vanillaJS/ES6 code.

HTML code example:

<div class ="a"></div>
<div class ="a"></div>
<div class ="a b"></div>
<div class ="a"></div>
<div class ="a b"></div>
<div class ="a"></div>
like image 617
ClassicError Avatar asked Jan 20 '17 20:01

ClassicError


1 Answers

Try querySelector instead.

document.querySelectorAll('.a.b');

This is likely your simplest solution.

like image 175
user2867288 Avatar answered Sep 23 '22 17:09

user2867288