Forum Moderators: open

Message Too Old, No Replies

switch visiblility DHTML

         

hoju312

8:55 pm on Jun 19, 2006 (gmt 0)

10+ Year Member



I have 2 div's, one visible and one hidden. How do I switch the two with a button? I want a button at the end of the 1st that, when clicked, with hide the 1st and make the 2nd visible.

alanderson

4:16 am on Jun 21, 2006 (gmt 0)

10+ Year Member



Not too tricky I think.

Youwill need to add some stuff to this if you are going to support Netscape 4 but I am sure with a little searching you can do that.

Give each div an id.
<div id=divone></div>
<div id=divtwo></div>

in javascript do something like this;

// style function

function style(id){
if(document.layers) {
path = document.layers[id];
} else if(document.all) {
path = document.all[id].style;
} else {
path = document.getElementById(id).style;
}
return path;
}

style('divone').visibility = "hidden";
style('divtwo').visibility = "visible";

For the css elements that have two words like "background_color:" you put the words in camel case like this

style('divtwo').backgroundColor = "red";

There it is a simple div styler.