Modern browsers already have this: element.classList.contains(name)