I'm just trying to make a list of questions with hidden answers that shows upon click. My code hides all divs, but when I click on the anchors, only the last box is toggled. In this case, every anchor toggles the 5th box, and not their own.
for(var i=1; i<6; i++){
var x = i+"";
$("#box"+ x).hide();
$("#feature"+x).click(function(){
$("#box"+x).toggle(400);
});
}
My basic HTML looks like this, but with 5 pairs:
<p><a id="feature1" href="#">1. Absent Message</a></p>
<div id="box1">Stuff here 1</div>
<p><a id="feature2" href="#">2. Alarm Setting</a></p>
<div id="box2">Stuff here 2</div>
If I wrote out the functions without using the for loop and string concatenation, the functions do what I want them to. Can someone point me in the right direction? Am I doing something wrong with the string manipulation?