Skip to content

Instantly share code, notes, and snippets.

@jlittlejohn
Created March 25, 2014 16:04
Show Gist options
  • Save jlittlejohn/9765051 to your computer and use it in GitHub Desktop.
Save jlittlejohn/9765051 to your computer and use it in GitHub Desktop.
JS: Toggle Buttons Utility Function
(function( $ ){
$.fn.toggleButtons = function() {
this.on('click', function(e) {
e.preventDefault();
var targetID = $(this).data('id');
if( $(targetID).hasClass('hide') ) {
$(targetID).toggleClass('hide');
} else {
$(targetID).toggle();
}
});
return this;
};
})( jQuery );
$('a.reveal').toggleButtons();
// <a class="reveal" data-id="#example"></a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment