Skip to content

Instantly share code, notes, and snippets.

@AndrePessoa
Created October 5, 2016 21:09
Show Gist options
  • Save AndrePessoa/dc48cf63ff2ecf08a0124a5e8006576d to your computer and use it in GitHub Desktop.
Save AndrePessoa/dc48cf63ff2ecf08a0124a5e8006576d to your computer and use it in GitHub Desktop.
Add/remove class pessoal
// class manipulation from http://www.openjs.com/scripts/dom/class_manipulation.php
function hasClass(ele,cls) {
return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
if( cls.split(' ').length > 1 ){
var clss = cls.split(' ');
for (var i = clss.length - 1; i >= 0; i--) {
removeClass( ele, clss[i] );
}
}else{
if (hasClass(ele,cls)) {
var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
ele.className=ele.className.replace(reg,'');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment