Created
December 16, 2014 19:47
-
-
Save celsofabri/f8e9957959c88ea92d96 to your computer and use it in GitHub Desktop.
Add and Remove Class with Javascript / Adicionar e Remover Classe com Javascript
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
var variavel = document.querySelector('.title-main'); | |
variavel.addEventListener('click', function() { | |
if(variavel.classList.contains('classe')) { | |
this.classList.remove('classe'); | |
} | |
else { | |
this.classList.add('classe'); | |
} | |
}); | |
// Or | |
variavel.addEventListener('click', function() { | |
this.classList.toggle('classe') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment