Created
          April 25, 2013 22:17 
        
      - 
      
 - 
        
Save rememberlenny/5463691 to your computer and use it in GitHub Desktop.  
    document class add
  
        
  
    
      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
    
  
  
    
  | $('body').addClass('hasJS'); | |
| // or | |
| document.body.className += ' hasJS'; | |
| We can do: | |
| document.body.classList.add('hasJS'); | |
| Isn’t that pretty? | |
| What about removing: | |
| $('body').removeClass('hasJS'); | |
| // or some crazy ass regular express | |
| Or we can do: | |
| document.body.classList.remove('hasJS'); | |
| But more impressive is the native toggle support: | |
| document.body.classList.toggle('hasJS'); | |
| // and | |
| document.body.classList.contains('hasJS'); | |
| To set multiple classes, you add more arguments: | |
| document.body.classList.add('hasJS', 'ready'); | |
| What does suck though, is the weird issues – like don’t use a empty string: | |
| document.body.classList.contains(''); | |
| // SyntaxError: DOM Exception 12 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment