Reputation: 1398
var items = document.getElementsByClassName("classname");
Gives me all the .classname
classes, how do I update the code to get all those classes but excluding .classname_exclude
?
Upvotes: 2
Views: 2081
Reputation: 240928
Rather than using the method .getElementsByClassName()
, you could use the method .querySelectorAll()
(which accepts CSS3 selectors) and use the :not()
pseudo class to negate those elements:
var items = document.querySelectorAll('.classname:not(.classname_exclude)');
Upvotes: 10