Created
December 20, 2017 16:57
-
-
Save MSerj/bc503554f81899fb005a12ced975eb13 to your computer and use it in GitHub Desktop.
get class list of element
This file contains hidden or 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
//You can use document.getElementById('divId').className.split(/\s+/); to get you an array of class names. | |
//Then you can iterate and find the one you want. | |
var classList = document.getElementById('divId').className.split(/\s+/); | |
for (var i = 0; i < classList.length; i++) { | |
if (classList[i] === 'someClass') { | |
//do something | |
} | |
} | |
//jQuery does not really help you here... | |
var classList = $('#divId').attr('class').split(/\s+/); | |
$.each(classList, function(index, item) { | |
if (item === 'someClass') { | |
//do something | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment