Learning a lot about Jquery every day. However it seems I can't for the life of me figure out how to display items in this multidimensional array one item at a time, while fading in and out of each one. *Note I don't wants these to append, just display one set, then fade out and fade in to the next set. Here's some info for you pros.
Basically Here I am storing what I have in my json Object named data into result. This seems to loop through each time as if i put alert(result['question']) it will give me each value one at a time, however when trying to apply this to my div, in which I am using a span class called .Active, it will just loop through the entire thing and give me the last item in the array. 2+2 lol duh 1 2. What I am doing wrong here?? If need be I will try to rig a jfiddle for it.
object coming from php page (called data)
[{"id":"238","question":"Which of these is a noun?","answer":"horse"},{"id":"238","question":"Which of these is a noun?","answer":"long"},{"id":"238","question":"Which of these is a noun?","answer":"pretty"},{"id":"238","question":"Which of these is a noun?","answer":"hair"},{"id":"238","question":"2+2 lol duh 1 2","answer":"4"}]
Code
for (var i = 0; i < data.length; i++) {
result = data[i];
console.log(result['question']);
liText += '<span><h5>'+result["question"]+'</h5>';
liText += '<p><b>Option: </b>'+result["answer"];
liText += '</p></span>';
$.each(result['question'], function(index) {
$(this).delay(400*index).fadeIn(300);
});
$('.Active').text(result['question']);
}
Console Log of result[question] *note these are correct, 5 different questions, the first 4 are the same.
Which of these is a noun?
index....mid=119 (line 227)
Which of these is a noun?
index....mid=119 (line 227)
Which of these is a noun?
index....mid=119 (line 227)
Which of these is a noun?
index....mid=119 (line 227)
2+2 lol duh 1 2
ps * a million respect points if you can get it to work with the liText I have above instead :)
edit*
When removing the .each and moving up some things around this seems to work, anyone that can help me first out the fadein and fade out of each I would appreciate it. Located in $('.Active')
for (var i = 0; i < data.length; i++) {
result = data[i];
alert(result['question']);
$('.Active').text(result['question']);