JQuery disappears in an array of objects - items one at a time

Learn a lot about jQuery everyday. However, it seems that I can’t understand all my life how to display elements in this multidimensional array, one element at a time, while they disappear and exit each. * Note. I do not want them to be added, just display one set, then disappear and disappear until the next set. Here is some information for you.

Basically here I store what I have in my json Object named data in result. It seems that each cycle repeats as if I set a warning (result ['question']), it will give me each value one at a time, however when I try to apply this to my div, in which I use the span class called .Active , it will just skip the whole thing and give me the last element of the array. 2 + 2 lol duh 1 2. What am I doing wrong here? If necessary, I will try to install jfiddle for it.

an object coming from a 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"}]

the 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:&nbsp;</b>'+result["answer"];

    liText += '</p></span>';


    $.each(result['question'], function(index) {
        $(this).delay(400*index).fadeIn(300);


    });
    $('.Active').text(result['question']);

    }

Console log of the result [question] * note that this is 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 points of respect, if you can make it work with liText, which I have higher :)

edit *

.each , , , , Fadein , . $('. Active')

for (var i = 0; i < data.length; i++) {
    result = data[i];
    alert(result['question']);
    $('.Active').text(result['question']);
0
1

:

for (var i = 0; i < data.length; i++) {
    result = data[i];

    var $question = $("<span>").text(result['question']).hide()
                               .delay(400*i).fadeIn(300);

    $('.Active').append($question);
}

liText, .

http://jsfiddle.net/Qf3FZ/

0

Source: https://habr.com/ru/post/1652070/


All Articles