Created
          October 5, 2016 21:09 
        
      - 
      
 - 
        
Save AndrePessoa/dc48cf63ff2ecf08a0124a5e8006576d to your computer and use it in GitHub Desktop.  
    Add/remove class pessoal
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | // 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