Hi,
I'm a novice... just trying figure out something simple, I'm sure.
I've got a script within my <head> tags to show/hide divs on click:
Using it as follows:
etc.
I was going to use <noscript> to expand all of the divs by default if the user had javascript disabled, but I've read that's the wrong way to go, so then I was going to reverse the layout to have the divs expanded by default (i.e. display:block) and then use script to collapse them on page load.
But I can't figure out if I can use this with onload="showHid e()" or something else. I want to be able to collapse all of the divs when the page loads, but my script is designed to expand/collapse an individual div on click. I've tried a few things but I'm terrible with syntax and I keep getting errors.
Suggestions?
I'm a novice... just trying figure out something simple, I'm sure.
I've got a script within my <head> tags to show/hide divs on click:
Code:
function showHide(divID, imgID){
if (document.getElementById(divID).style.display == "none") {
document.getElementById(divID).style.display = "block";
document.getElementById(imgID).src = "http://bytes.com/images/collapse.gif";
} else {
document.getElementById(divID).style.display = "none";
document.getElementById(imgID).src = "http://bytes.com/images/expand.gif";
}
}
Code:
<div class="areacode"><img id="416image" src="http://bytes.com/images/expand.gif" onclick="showHide('416',this.id)"/> AREA CODE 416</div>
<div id="416" style="display:none">
I was going to use <noscript> to expand all of the divs by default if the user had javascript disabled, but I've read that's the wrong way to go, so then I was going to reverse the layout to have the divs expanded by default (i.e. display:block) and then use script to collapse them on page load.
But I can't figure out if I can use this with onload="showHid e()" or something else. I want to be able to collapse all of the divs when the page loads, but my script is designed to expand/collapse an individual div on click. I've tried a few things but I'm terrible with syntax and I keep getting errors.
Suggestions?
Comment