The code
function hasClass(element, className) { var regex = new RegExp('\\b' + className + '\\b'); do { if (regex.exec(element.className)) { return true; } element = element.parentNode; } while (element); return false; } OR
function hasClass(element, className) { do { if (element.classList && element.classList.contains(className)) { return true; } element = element.parentNode; } while (element); return false; }