Tags on Tags off

Use this to turn any classes or ids off easily declared in the tag itself.


 if (typeof ons_and_offs != 'function') { //1126PM

	 function ons_and_offs() {
	 
		$( ".class_on_off" ).click(function() { //2AM ON AND OFF

		  var what        = $(this).attr("data-what");
		  if (what == "parent") { what =  $(this).parent(); }
		  if (what == "this")   { what =  $(this); }
		  var what_class      = $(this).attr("data-what-class");
		  var what_class_off  = $(this).attr("data-what-class-off");
		  var has_class       = false;
		  if ($(what).hasClass( what_class )) { has_class   = true; }
          if (what_class_off != "undefined") { $( what_class_off ).removeClass( what_class ); }
		  
		  
		  if (has_class == false) {
		      $(what).addClass(what_class);
		  }else{
		      $(what).removeClass(what_class);
		  }
		   
		}); //2AM ON AND OFF
		 
		$( ".tags_on" ).click(function() { //1676AM
		 
		  var tags_on    = $(this).attr("data-tags-on");
		      tags_on    = tags_on.split(',');
		      tags_on.forEach(function(tag) {
		            $(tag).show();
		      });
		 
		}); //1676AM
		 
		$( ".tags_off" ).click(function() { //1456AM

		  var tags_off    = $(this).attr("data-tags-off");
		      tags_off    = tags_off.split(',');
		      tags_off.forEach(function(tag) {
		            $(tag).hide();
		      });
		 
		}); //1456AM 
	 
	 }
	 
	 ons_and_offs(); 
 
 } //1126PM

Comments