(function($) {
////////////////////////////////////////////////////////
//////////////////// TOGGLE PANELS /////////////////////
////////////////////////////////////////////////////////
var $jsToggle = $('.js-toggle'),
allPanels = new Array(), // empty array
panelID,
removePanel;
// when page loads find all hrefs using the class of .js-toggle
// using push, update the empty array for later use
// replace hash with a period to make it look like a class selector
$jsToggle.each(function(){
allPanels.push($(this).attr('href').replace(/^#/, '.'));
});
function togglePanels(e) {
// make sure the href doesn't appear in the address bar
e.preventDefault();
// save the value of the href as a variable
var panelID = $(this).attr('href').replace(/^#/, '.');
// remove the current panel from the allPanels array
removePanel = allPanels;
removePanel = $.grep(removePanel, function(value) {
return value != panelID;
});
// close all other panels
$(removePanel.join(", ")).removeClass('js-animation');
// toggle the panel
$(panelID).toggleClass('js-animation');
}
$jsToggle.on('click', togglePanels);
})(jQuery);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.