Last active
August 29, 2015 14:04
-
-
Save DenimTornado/df58efbdf2bf18854247 to your computer and use it in GitHub Desktop.
Adding custom class to an element
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
var add_class = function(element, classname) { | |
var class_name = element.className; | |
//test for existance | |
if( class_name.indexOf( classname ) !== -1 ) { | |
return; | |
} | |
//add a space if the element already has class | |
if( class_name !== '' ) { | |
classname = ' '+classname; | |
} | |
element.className = class_name+classname; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment