Hi,
I am giving you some hint. try it and fit this in your solution.
Put you question and answers in div like this
<div id='div_FAQ_Question_1' class='FAQ_Question' onclick='fnShowHideFAQ(this)'>
Question 1
</div>
<div id='div_FAQ_Answer_1' class='FAQ_Answer'>
Anwser 1
</div>
<div id='div_FAQ_Question_2' class='FAQ_Question' onclick='fnShowHideFAQ(this)'>
Question 2
</div>
<div id='div_FAQ_Answer_2' class='FAQ_Answer'>
Anwser 2
</div>
<div id='div_FAQ_Question_3' class='FAQ_Question' onclick='fnShowHideFAQ(this)'>
Question 3
</div>
<div id='div_FAQ_Answer_3' class='FAQ_Answer'>
Anwser 3
</div>
Use CSS
.FAQ_Answer
{
display: none;
}
Finally define js function
function fnShowHideFAQ(obj) {
var currentQuestionId = obj.id;
var currentAnswerId = currentQuestionId.replace('Question', 'Answer');
var currentAnswerStatus = $('#' + currentAnswerId).css('display');
$('.FAQ_Answer').css('display', 'none');
if (currentAnswerDisplay == 'none') {
$('#' + currentAnswerId).css('display', '');
}
}
js function works like this
1. when you click on a question it gets question id and finds answer id.
2. stores current status of answer (is it hidden or showing).
3. hide all answer.
4. if current answer is not visible, function makes it visible.
Note:- use same css class for all answers, because its hide all elements which has class 'FAQ_Answer'.
Suggestion:- you can use onclick='fnShowHideFAQ(this)' in answer div also. this will hide current answer if you click on current answer.
All the best