Skip to content

Instantly share code, notes, and snippets.

@kevsimpson
Created July 31, 2014 21:06
Show Gist options
  • Select an option

  • Save kevsimpson/570147a41bcc6371fd6e to your computer and use it in GitHub Desktop.

Select an option

Save kevsimpson/570147a41bcc6371fd6e to your computer and use it in GitHub Desktop.
jQuery: Toggle class via data-toggle
var toggleClass = function(el, className) {
if(el.hasClass(className + '--open')) {
el.removeClass(className + '--open');
} else {
el.addClass(className + '--open');
}
}
$('[data-toggle]').on( "click", function() {
var $className = $( this ).data("toggle");
toggleClass($('html'), $className);
});
// use <button data-toggle="nav--main">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment