Skip to content

Instantly share code, notes, and snippets.

@electerious
Created September 16, 2017 13:57
Show Gist options
  • Save electerious/9399d130b0ade5cbfaa9f537fbc06b8a to your computer and use it in GitHub Desktop.
Save electerious/9399d130b0ade5cbfaa9f537fbc06b8a to your computer and use it in GitHub Desktop.
Checks if an element has any of multiple classes
const hasClassNames = (elem, classNames) => classNames.filter((className) => elem.classList.contains(className)).length>0
@electerious
Copy link
Author

electerious commented Sep 16, 2017

Example:

const elem = document.querySelector('.elem')
const classNames = [ 'elem', 'or', 'another', 'class' ]

hasClassNames(elem, classNames) // true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment