Skip to content

Instantly share code, notes, and snippets.

@think49
Last active February 17, 2016 03:25
Show Gist options
  • Save think49/c382098fedd9ae7c6661 to your computer and use it in GitHub Desktop.
Save think49/c382098fedd9ae7c6661 to your computer and use it in GitHub Desktop.
jquery.get-classlist.js: jQuery オブジェクトの最初のインデックスとなる要素ノードから classList (HTML5規定) を得る jQuery plugin
/**
* jquery.get-classlist.js
* get a classList of first index's jQuery object.
*
* @version 1.0
* @author think49
* @url https://gist.github.com/think49/c382098fedd9ae7c6661
* @license http://www.opensource.org/licenses/mit-license.php (The MIT License)
*/
jQuery.fn.getClassList = function getClassList () {
var element;
if (this.length < 1) {
return [];
}
element = this[0];
return 'classList' in element ? element.classList : element.className.split(/\s+/);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment