Hide/Show Issue, Please Help

E

Erik Lautier

I have several pairs of DIVS on my page, and I'm trying to modify some
code such that when the first of a pair is clicked (let's call it
div1), it hides itself and shows div2; if div2 is clicked, it hides
itself and shows div 1. The same would happen for div3 and div4, div5
and div6, etc. The numbers appending "div" will be dynamically
generated and the pairs will be two sequential numbers (though there
may be larger gaps between the sets of pairs).

The code thus far is:

function hidediv(id) {
//safe function to hide an element with a specified id
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById(id).style.display = 'none';
}
else {
if (document.layers) { // Netscape 4
document.id.display = 'none';
}
else { // IE 4
document.all.id.style.display = 'none';
}
}
}

The obviously hides the div that's been clicked, so the problem I'm
having is showing the "next" div. The other function showdiv(), simply
does the reverse. How do I get javascript to find the next or previous
div? Thanks.
 
R

Randy Webb

Erik Lautier said the following on 11/10/2006 12:57 PM:
I have several pairs of DIVS on my page, and I'm trying to modify some
code such that when the first of a pair is clicked (let's call it
div1), it hides itself and shows div2; if div2 is clicked, it hides
itself and shows div 1. The same would happen for div3 and div4, div5
and div6, etc. The numbers appending "div" will be dynamically
generated and the pairs will be two sequential numbers (though there
may be larger gaps between the sets of pairs).

The code thus far is:

function hidediv(id) {
//safe function to hide an element with a specified id
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById(id).style.display = 'none';

There is nothing "safe" about the above two lines of code.
}
else {
if (document.layers) { // Netscape 4
document.id.display = 'none';
}
else { // IE 4
document.all.id.style.display = 'none';
}
}
}

All of the above code can be dropped.
The obviously hides the div that's been clicked, so the problem I'm
having is showing the "next" div. The other function showdiv(), simply
does the reverse. How do I get javascript to find the next or previous
div? Thanks.

Read the digit at the end of it, and add/subtract one based on whether
its odd or even.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top