The Herculoids
Herculoids A real groovy bunch of superheroes from Hanna-Barbera, circa 1967. For more about Gloop, Tara, and the rest of my old friends, click the link to check out Mr. Markstein's Toonopedia website.
Home Services Toolbox Downloads Gaming Tech News About Us

Open and Close DIV Layers












Open/Close Div Layers

This code snippet demonstrates using a 'container' div, which can be expanded or collapsed to show/hide blocks of content.

For my javascript function names, I pondered items that are opened and closed. I considered eyes, cupboards, drawers, even silly sock hand puppets, but finally decided upon a lunchbox. If I were a betting man, I'd be willing to bet that everyone who sees this webpage has owned, or at least seen, a lunchbox. Purt' near 70 years have passed since I was a lunchbox-toting lad, but I vaguely recall my favorite lunchbox - it was a real dandy depicting a team of superheroes known as The Herculoids. I was particularly fond of Gloop and Gleep, those darn cute little blobby things. But I digress...

Pack the Lunchbox (HTML)

First, we'll create the HTML, consisting of a pair of <div> layers for each lunchbox. The first <div> layer (clasp_x) will use a hyperlink to trigger our javascript function that displays the contents of the second <div> (lunch_x). I've supplied the code for two lunchboxes below, but you can add as many more as you like, by incrementing the numeric suffix (x) of each pair of layer id's. Now you can add this HTML code to your page:
<div id="clasp_1" class="clasp"><a href="javascript:lunchboxOpen('1');">Open Lunchbox 1...</a></div>
<div id="lunch_1" class="lunchbox">This is lunchbox 1<br />Peanut Butter & Jelly<br />Potato Chips<br />Apple</div>
<div id="clasp_2" class="clasp"><a href="javascript:lunchboxOpen('2');">Open Lunchbox 2...</a></div>
<div id="lunch_2" class="lunchbox">This is lunchbox 2<br />Liverwurst (bleh!)<br />Twinkies<br />Fig Newtons</div>

Hide the Lunchbox (CSS)

Next, we'll create a couple of CSS classes, one of which will hold the hyperlink, and another whose contents are initially not displayed on the web page. Add these class definitions to your CSS stylesheet:
.clasp {
text-align:center;
}
.lunchbox {
display:none;
}

Miami Dolphins Ryan Tannehill 10" Player Plush Doll,'47 Brand Atlanta Falcons Iconic Reversible Cuffless Knit Hat - Black/Red.Men's San Francisco 49ers New Era Scarlet Premium 59FIFTY Fitted Hat,Women's Green Bay Packers Faux Fur Long Scarf with Pockets.Women's San Francisco 49ers Majestic Pink Draft Me VII T-Shirt,Mens Oakland Raiders Antigua Black Volt Crew Sweatshirt Nike San Diego Chargers Womens Jerseys.Mens Minnesota Vikings '47 Brand Black Franchise Fitted Hat,Infant New Orleans Saints 2-Pack Glow Pacifier.New York Giants Core Logo Extra Small Duffle Bag - Royal Blue,Men's Philadelphia Eagles Pro Line Heather Grey Throwback II Big & Tall Long Sleeve T-Shirt,Men's Houston Texans Majestic Red Critical Victory Pullover Hoodie San Diego Chargers History.Toddler Pittsburgh Steelers Ben Roethlisberger Nike Black Game Jersey,Women's Oakland Raiders White Sublime Burnout V-Neck Long Sleeve T-Shirt Philip Rivers Of The San Diego Chargers.Detroit Lions WinCraft 2-Pack 4" x 4" Decals,Men's Kansas City Chiefs Klew Red Gradient Shorts Cheap San Diego Chargers Nfl Jerseys Sale.Women's Cleveland Browns Historic Logo Majestic Black Lateral Sprint VI Pants,Men's Pittsburgh Steelers Cutter & Buck Black Mason Full-Zip WeatherTec Jacket,Women's Tampa Bay Buccaneers '47 Brand Red Clovis Cadet Adjustable Hat

Open & Close the Lunchbox (javascript)

All that remains is to define two javascript functions - lunchboxOpen() and lunchboxClose() - which can be either in the <head> area of your HTML page, or in a separate javascript file:
function lunchboxOpen(lunchID) {
document.getElementById('lunch_' + lunchID).style.display = "block";
document.getElementById('clasp_' + lunchID).innerHTML="<a href=\"javascript:lunchboxClose('" + lunchID + "');\">Close Lunchbox " + lunchID + "...</a>";
}
function lunchboxClose(lunchID) {
document.getElementById('lunch_' + lunchID).style.display = "none";
document.getElementById('clasp_' + lunchID).innerHTML="<a href=\"javascript:lunchboxOpen('" + lunchID + "');\">Open Lunchbox " + lunchID + "...</a>";
}

Enjoy your Lunchbox!

Below are sample implementations of the lunchbox code. Depending on the CSS styles you apply to the clasp and lunchbox classes, you can achieve a variety of different looks.

Example 1

This is lunchbox 1
Peanut Butter & Jelly
Potato Chips
Apple
This is lunchbox 2
Liverwurst (bleh!)
Twinkies
Fig Newtons
This is lunchbox 3
Tuna Salad
Snack Pack Pudding
Carrots

Example 2

This is lunchbox 4
Peanut Butter & Jelly
Potato Chips
Apple
This is lunchbox 5
Liverwurst (bleh!)
Twinkies
Fig Newtons
This is lunchbox 6
Tuna Salad
Snack Pack Pudding
Carrots

Example 3

This is lunchbox 7
Peanut Butter & Jelly
Potato Chips
Apple
This is lunchbox 8
Liverwurst (bleh!)
Twinkies
Fig Newtons
This is lunchbox 9
Tuna Salad
Snack Pack Pudding
Carrots

Home Services Toolbox Downloads Gaming Tech News About Contact Us Privacy