Skip to content

Instantly share code, notes, and snippets.

@hidegh
Created July 30, 2019 07:43
Show Gist options
  • Save hidegh/c3e16685723ba6e6dd91293774011a52 to your computer and use it in GitHub Desktop.
Save hidegh/c3e16685723ba6e6dd91293774011a52 to your computer and use it in GitHub Desktop.
Allows to toggle/add/remove classes of an HTML element...
$(document).on('click', '[data-toggle="class"]', function () {
var $target = $($(this).data('target'));
var toggleClasses = $(this).data('toggle-classes');
if (toggleClasses)
$target.toggleClass(toggleClasses);
var addClass = $(this).data('add-classes');
if (addClass)
$target.addClass(addClass);
var removeClass = $(this).data('remove-classes');
if (removeClass)
$target.removeClass(removeClass);
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment