HTML Help Forum HTML Help
Please Search for the answer to your question before asking it! Thanks.
 

HTML code for FAQ page - how to hide answers
Post a Reply to this Topic Ask a New Question
Click here to go to the original topic
       HTML Help Forum -> HTML Form
View previous topic :: View next topic  
Author Message
thyme



Joined: 13 Sep 2009
Posts: 1

Posted: Sun Sep 13, 2009 11:33 am     HTML code for FAQ page - how to hide answers  

I am looking for a code on my FAQ page to keep the page clean. What I want is to have the user click on the question THEN the answer will appear. IE when they click on the question the second time, the answer will go back to being hidden.
sticks464



Joined: 31 Dec 2006
Posts: 2625

Posted: Sun Sep 13, 2009 1:22 pm      

Try the jquery FAQ plugin.

Demo here
gary.newelluk



Joined: 12 May 2005
Posts: 552
Location: Inverurie, Scotland

Posted: Sun Sep 27, 2009 1:50 pm      

Hi, I have written this fairly quickly but it seems to work ok in Firefox so give it a go.

Code:
<html>
<head>
<title>Test FAQs</title>
<script type="text/javascript">
function toggleview(itm)
{
   var itmx = document.getElementById(itm);
   if (itmx.style.display == "none")
   {
      itmx.style.display = "block";
   }
   else
   {
      itmx.style.display = "none";
   }
}
</script>
</head>
<body>
<a href="#" onclick="toggleview('q1')">1. How do I hide the answer when I click here</a>
<div id='q1' style="display:none">
Look at this code
</div>
</body>
</html>


Basically for each question create an <a> tag with an onclick event which calls toggleview with the question number.

Create a div section with an id set to the question number. IE q1, q2, q3 etc
 
 
DARFUR
HOSTING / DESIGN
MAKE MONEY

       HTML Help Forum -> HTML Form
Page 1 of 1


Powered by phpBB Search Engine Indexer
Powered by phpBB 2.0.19 © 2001, 2002 phpBB Group