Last active
March 5, 2016 11:25
-
-
Save yairEO/295af5e749f38cd80fdc to your computer and use it in GitHub Desktop.
checks if an element has a class(s)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Element.prototype.hasClass = Element.prototype.hasClass || | |
function(classArr){ | |
var hasClass = 0, | |
className = this.getAttribute('class'); | |
if( this == null || !classArr || !className ) return false; | |
if( !(classArr instanceof Array) ) | |
classArr = classArr.split(' '); | |
for( var i in classArr ) | |
// this.classList.contains(classArr[i]) // for modern browsers | |
if( className.split(classArr[i]).length > 1 ) | |
hasClass++; | |
return hasClass == classArr.length; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment