Skip to content

Instantly share code, notes, and snippets.

@celsofabri
Created December 16, 2014 19:47
Show Gist options
  • Save celsofabri/f8e9957959c88ea92d96 to your computer and use it in GitHub Desktop.
Save celsofabri/f8e9957959c88ea92d96 to your computer and use it in GitHub Desktop.
Add and Remove Class with Javascript / Adicionar e Remover Classe com Javascript
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