Skip to content

Instantly share code, notes, and snippets.

@rg3915
Created April 3, 2017 05:44
Show Gist options
  • Save rg3915/321c3ae4d7225a896aeadacef230ac39 to your computer and use it in GitHub Desktop.
Save rg3915/321c3ae4d7225a896aeadacef230ac39 to your computer and use it in GitHub Desktop.
fadeToggle
<button class="btn btn-success mybtn">Ocultar</button>
<p>Com o comando <code>fadeToggle()</code> podemos ocultar ou mostrar um elemento.</p>
// Alterna o texto de um elemento.
$.fn.extend({
toggleText: function(a, b) {
return this.text(this.text() == b ? a : b);
}
});
$(".mybtn").on('click', function(e) {
e.preventDefault();
// Pega o próximo elemento, no caso o primeiro parágrafo.
$(this).next().fadeToggle('slow', 'linear');
$(this).toggleText('Ocultar', 'Mostrar');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment