// jQuery hide()/show() example with a switch statement
$(document).ready(function() {
// function to hide all divs
function hideAll() {
$('#elephantStuff').hide();
$('#rhinoStuff').hide();
$('#zebraStuff').hide();
$('#lionStuff').hide();
}
// run that function right away
hideAll();
// when any animal is clicked, make the suitable div appear
$('.animalIcon').click(function() {
// but first, hide all the divs to ensure that
// only one will be open, ever
hideAll();
// here is a switch statement - this was in Codecademy
// "Control Flow" lesson 7
// we can get the ID of the thing that was clicked -
switch ($(this).attr("id")) {
case "theElephant":
$('#elephantStuff').show();
break;
case "theRhino":
$('#rhinoStuff').show();
break;
case "theZebra":
$('#zebraStuff').show();
break;
case "theLion":
$('#lionStuff').show();
break;
}
}); // end of function for clicking
});
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.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path.
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!