FAQ-page => showing/hiding text

D

Dré

Hi,

I'm making a FAQ-page. To keep it a little synoptic, only the questions are
visible. When you klick on a certain question, the answer appears. You can
find an example at: http://www.aendekerk.be/zoom/uitklappen.htm

Suppose i click on "titel1", "tekst1" appears. When i click on "titel2",
"tekst2" appears. But also tekst1 remains visible. I don't want this. How
can i program this?

Thanks!

Dries
 
E

Evertjan.

Dré wrote on 09 feb 2004 in comp.lang.javascript:
I'm making a FAQ-page. To keep it a little synoptic, only the
questions are visible. When you klick on a certain question, the
answer appears. You can find an example at:
http://www.aendekerk.be/zoom/uitklappen.htm

Suppose i click on "titel1", "tekst1" appears. When i click on
"titel2", "tekst2" appears. But also tekst1 remains visible. I don't
want this. How can i program this?

function openen(x) {
s='none'
document.getElementById('text1').style.display=s
document.getElementById('text2').style.display=s
document.getElementById('text3').style.display=s
document.getElementById('text4').style.display=s
document.getElementById('text5').style.display=s

document.getElementById(x).style.display=''
}


<div onclick="openen('text1')">titel van text1</div>
<div id="text1">...........</div>

niet getest, hoor.
 
B

Bas Cost Budde

Dré said:
Hi,

I'm making a FAQ-page. To keep it a little synoptic, only the questions are
visible. When you klick on a certain question, the answer appears. You can
find an example at: http://www.aendekerk.be/zoom/uitklappen.htm

Suppose i click on "titel1", "tekst1" appears. When i click on "titel2",
"tekst2" appears. But also tekst1 remains visible. I don't want this. How
can i program this?

Thanks!

Dries
Keep the ID of the opened question in a public variable, and on click of
an item first close the opened one.
 
D

Dré

I'm making a FAQ-page. To keep it a little synoptic, only the questions are
visible. When you klick on a certain question, the answer appears. You can
find an example at: http://www.aendekerk.be/zoom/uitklappen.htm

Suppose i click on "titel1", "tekst1" appears. When i click on "titel2",
"tekst2" appears. But also tekst1 remains visible. I don't want this. How
can i program this?

I've found a solution on
http://www.dynamicdrive.com/dynamicindex1/navigate2.htm
Thanks anyway for replying!!

Dries
 
R

Richard Cornford

Keep the ID of the opened question in a public variable,
and on click of an item first close the opened one.

Rather than saving the ID of the element that needs to be re-hidden as a
string in a global variable it would be more efficient to save a
reference to the element, or, better yet, its style object. It would
save having to re-locate the element within the DOM (getElementById is
not necessarily that fast). The script must have had that reference when
it made the element visible so it can just assign the reference at that
point, having defaulted the global variable to null. Then if the
variable refers to an object when it is time to make a different element
visible it is a simple matter to first render the stored element hidden.

Richard.
 
B

Bas Cost Budde

Rather than saving the ID of the element that needs to be re-hidden as a
string in a global variable it would be more efficient to save a
reference to the element, or, better yet, its style object.

Thanks. Showing my javascript age here :)
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top