Skip to content

Instantly share code, notes, and snippets.

@eightHundreds
Created October 12, 2017 07:32
Show Gist options
  • Save eightHundreds/6f9c2990ba4cbf6a93682ee4583060ed to your computer and use it in GitHub Desktop.
Save eightHundreds/6f9c2990ba4cbf6a93682ee4583060ed to your computer and use it in GitHub Desktop.
function hasClass( elements,cName ){
return !!elements.className.match( new RegExp( "(\\s|^)" + cName + "(\\s|$)") );
};
function addClass( elements,cName ){
if( !hasClass( elements,cName ) ){
elements.className += " " + cName;
};
};
function removeClass( elements,cName ){
if( hasClass( elements,cName ) ){
elements.className = elements.className.replace( new RegExp( "(\\s|^)" + cName + "(\\s|$)" ), " " );
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment