Skip to content

Instantly share code, notes, and snippets.

View artemean's full-sized avatar

Andrii Artemenko artemean

View GitHub Profile
@jjmu15
jjmu15 / has_class.js
Created January 27, 2014 10:08
has class function - vanilla JS. Check if element has specified class
// hasClass, takes two params: element and classname
function hasClass(el, cls) {
return el.className && new RegExp("(\\s|^)" + cls + "(\\s|$)").test(el.className);
}
/* use like below */
// Check if an element has class "foo"
if (hasClass(element, "foo")) {