Last active
August 3, 2019 20:35
-
-
Save matthewstokeley/69a011d678625529a2aade6a8a1c823c to your computer and use it in GitHub Desktop.
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
/** | |
* This method is several years old and is being produced here to continue the discussion | |
* about what is considered production-level element attribute toggling. | |
* | |
* Both jQuery and twbs are widely used in production sites and can be used | |
* as standards for production-level acceptance criteria. | |
* | |
* jQuery is similar to this method - it looks for | |
* classList first and then falls back to className. | |
* | |
* twbs4 only uses the classList object in components, | |
* possibly because classList has been a standard for several years. | |
* | |
*/ | |
( function( _elements ) { | |
/** | |
* | |
* @param {Element} element | |
* @param {String} className | |
*/ | |
var addClass = function( element, className ) { | |
if ( element.nodeType !== 1 ) { | |
throw new Error('Invalid Argument Type'); | |
} | |
if ( element.classList && element.classList.add ) { | |
element.classList.add( className ); | |
} else if ( element.className ) { | |
element.className = element.className + ' ' + className; | |
} | |
return element; | |
}; | |
})( _elements ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment