ok, so I have a structure like two divs. On the left side div I have a list of 10 questions, and on the right hand side I want to populate the answers for the same. On clicking the question1 on the left hand side the answer should display in the right hand side. On clicking the second question the answer for second should display, hiding all the answers. so what would be the ideal way to do it in jquery.
I wrote something like;
$("document").ready(function() {
$("#idQ1").click(function() {
$("#ansQ1").css("display","block");
$("#ansQ1,#ansQ2,#ansQ3,#ansQ4,#ansQ5,.......#ansQ10").css("display","none");
})
})
but I dont think this code is good. can somebody guide as to how you would do this using loops or functions
The other answers are dead on with using classes to write an efficient script for this
I’ve created my own example here that uses anchor tags for the questions with an
hrefset to the id of an answer element.example here: http://jsfiddle.net/pxfunc/zEwUB/
HTML:
jQuery: