The first bit within <script type="text/javascript"> and </script> is the javascript function called toggleLayer that does the div switching.
The second bit (coloured orange above) within the <style type="text/css"> and </style> is the CSS style that initially hides the layer called SwitchPic. This name is just the name I will give to the picture layer. You can change the name of your layer to anything you want as long as you use the same name for the div later on.
Another thing to note with the second bit is that this is the code that tells the browser that the layer called SwitchPic is not displayed by default (display: none;) and that the z-index value is 99 (z-index: 99;). The value is basically the number that governs how far forward an element is on the page - a higher number means it is further forward. So a value of 99 indicates that SwitchPic is right at the front of the page, but currently is not set to display.
Now that you understand that, all the function in the first bit does is set the display property of SwitchPic so that it is displayed. And because its z-index is going to be higher than anything else on the iWeb page, it will be at the front!
Code in <body>
1. Name the div
Now you need to identify the <div> tag that contains our picture so that we can name it SwitchPic in order that the function knows that this is the element on the page that needs displaying.
Because you made the HTML changes to load the picture in the first place (i.e., the bit where you replaced PIC_CODE_HERE), you should be able to recognise the correct div. In my case, this will be the div that contains the <a href="http://www.rowan-cottage.co.uk/Site/Sitemap.html"><img src="http://www.rowan-cottage.co.uk/resources/images/divswitchpic.jpg" width="200" height="200" border="0" /></a> code as shown above.
You need to identify the series of divs surrounding this div that will all be switched at once. The correct series will have an id and a z-index. They will look something like this:
<div class="graphic_textbox_style_default" style="height: 200px; left: 574px; position: absolute; top: 442px; width: 200px; z-index: 1; " id="id1">
<div>
<div class="graphic_textbox_layout_style_default">
<div class="paragraph Body" style="line-height: 19px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0pt; padding-top: 0pt; text-align: left; text-indent: 0px; color: #cccccc; font-family: 'ArialMT', 'Arial', 'sans-serif'; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 0; line-height: 19px; opacity: 1.00; text-decoration: none; text-transform: none;"><a href="http://www.rowan-cottage.co.uk/Site/Sitemap.html"><img src="http://www.rowan-cottage.co.uk/resources/images/divswitchpic.jpg" width="200" height="200" border="0" /></a></div>
</div>
</div>
</div>
As I said you need to name this div with the name SwitchPic so that the function knows this is the correct series of divs to switch. You do this by changing id="id1" to id="SwitchPic" in the first <div> tag. Also you need to get rid of the z-index: 1; bit because as we've discussed earlier, SwitchPic already has an z-index of 99 as defined in the <head> section of the page. So now it will look like this:
<div class="graphic_textbox_style_default" style="height: 200px; left: 574px; position: absolute; top: 442px; width: 200px; " id="SwitchPic">
<div>
<div class="graphic_textbox_layout_style_default">
<div class="paragraph Body" style="line-height: 19px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0pt; padding-top: 0pt; text-align: left; text-indent: 0px; color: #cccccc; font-family: 'ArialMT', 'Arial', 'sans-serif'; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 0; line-height: 19px; opacity: 1.00; text-decoration: none; text-transform: none;"><a href="http://www.rowan-cottage.co.uk/Site/Sitemap.html"><img src="http://www.rowan-cottage.co.uk/resources/images/divswitchpic.jpg" width="200" height="200" border="0" /></a></div>
</div>
</div>
</div>
Notice particularly the position of all the inverted commas ". Make sure they are in the correct place otherwise it may not work.
HELP! I know you’re reading this and thinking, nah, this is far too difficult to continue with. Don’t worry! I’m only showing you all this code to illustrate the nested divs. Bear in mind you are only making changes to the first bit of this code, the enclosing div. There, that’s clear as mud isn’t it? :-) DON’T PANIC
2. Modify the hyperlink
Now we are going to change the DEMO link you set up in Initial Setup in iWeb above so that it calls the javascript function toggleLayer.
Find the DEMO link in the HTML page.
It should look something like this:
<a href="Home.html" title="Home.html" style="line-height: 20px; opacity: 1.00; ">DEMO</a>
In this case, don't worry about the surrounding <div> tags, we're not interested in those at all.
Now change the above to this:
<a href="javascript:toggleLayer('SwitchPic');" title="Click here to see a demo of div switching!" style="line-height: 20px; opacity: 1.00; ">DEMO</a>
You can see I replaced the first Home.html (the link) with javascript:toggleLayer('SwitchPic'); so that this javascript function will be called whenever you click on the DEMO link. And the second Home.html (the tool-tip pop-up text) I replaced with Click here to see a demo of div switching! so that you will see this whenever you hover over the link. The rest of the link is unchanged.
Now save the HTML file.
If you look at the page now in a browser, it should look like my demo at the of the page.
Now try the link! It should work to switch between the picture and text.
If you get the hang of this technique, you can use it to swap in and out all sorts of things, including external sources in iframes, other pages from within your site or just another block of text. As you can also see, you can incorporate links into both layers in the switch. You can also make buttons and other images into toggle links and if you are feeling really adventurous you could embed a toggle link in each of the layers of the div switch so that clicking it would take you to the other layer!
Finally...