Doug wrote:
Hi -
I'm looking to code some javascript that has an event handler tied to
an image ("a down arrow") that will expand code that was hidden on
the page load. It's pretty simple...
Easy for you to say. #:-0
I have an accessories html table that I
want to load in the html but hide to save page real estate until you
click the "down arrow" image. I know I've seen stuff like this
before, can anyone point me to an example of this or give me an idea of how
to code it?
Thanks, Doug
Maybe...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<base href="http://www.grsites.com/webgraphics/arrows/oy/">
<style type="text/css">
td.arrow {
width: 20px;
height: 20px;
cursor: pointer;
vertical-align: top;
text-align: center;
padding-top: 8px;
border: 1px #aa0 solid;
background: #aaa;
}
td.content {
width: 300px;
height: 20px;
font: 12px arial;
padding: 6px;
border: 1px #000 solid;
background: #ddd;
}
td h5 {
font: 11px arial;
letter-spacing: .5em;
margin: 0 0 8px 4px;
}
td div {
display: none;
}
#pload {
background: url(arrows_oy_026.gif);
display: none;
}
</style>
<script type="text/javascript">
function init()
{
var t, td, tds, i = 0;
if (document.getElementById
&& (t = document.getElementById('foo'))
&& (tds = t.getElementsByTagName('td')))
{
while (td = tds.item(i++))
{
td.onclick = function()
{
var img = this.getElementsByTagName('img').item(0);
var div = this.parentNode.getElementsByTagName('div').item(0 );
if (img && div)
{
var bWhich = /((^$)|(none))/.test(div.style.display);
div.style.display = bWhich ? 'block' : 'none';
img.src = bWhich ?
'arrows_oy_025.gif' : 'arrows_oy_026.gif';
}
}
}
}
}
window.onload = init;
</script>
</head>
<body>
<span id="pload"></span>
<table id="foo">
<tbody>
<tr>
<td class="arrow">
<img
src="http://www.grsites.com/webgraphics/arrows/oy/arrows_oy_026.gif">
</td>
<td class="content">
<h5>Item 1</h5>
<div>
....blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah....
</div>
</td>
</tr>
<tr>
<td class="arrow">
<img
src="http://www.grsites.com/webgraphics/arrows/oy/arrows_oy_026.gif">
</td>
<td class="content">
<h5>Item 2</h5>
<div>
....blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah....
</div>
</td>
</tr>
<tr>
<td class="arrow">
<img
src="http://www.grsites.com/webgraphics/arrows/oy/arrows_oy_026.gif">
</td>
<td class="content">
<h5>Item 3</h5>
<div>
....blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah....
</div>
</td>
</tr>
</tbody>
</table>
</body>
</html>