Skip to content

Instantly share code, notes, and snippets.

@aviogreen
Last active August 29, 2015 14:23
Show Gist options
  • Save aviogreen/7c5d0089260ef923db00 to your computer and use it in GitHub Desktop.
Save aviogreen/7c5d0089260ef923db00 to your computer and use it in GitHub Desktop.
/*******************************************************
:: Toggle Class
data-toggle="class"
data-class=""
data-target=".asd"
*******************************************************/
$('[data-toggle=class]').each(function(index, el) {
$(this).click(function(){
var target = null;
var the_class = $(this).data('class');
if( $(this).data('target') == '' ){
$(this).toggleClass(the_class);
} else if( $(this).data('target') == 'parent' ){
$(this).parent().toggleClass( the_class );
} else {
if( $($(this).data('target')).length )
$($(this).data('target')).toggleClass( the_class );
}
return false
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment