sparkle
sparkle

Reputation: 7398

JQuery each: Pause & Continue iteration after a click

$.getJSON('http://example.com', function(data) {

  $.each(data.songs, function(index, song) { 

    //Paused & waiting for a click

    $("#next").click(function() {
         alert("Processing the next object...");
    });

 });

I would that JQuery analyze the next object only after the user click on #next element.

I don't need a "timeout", just user action to go to the next object

Upvotes: 0

Views: 975

Answers (1)

TimD
TimD

Reputation: 1381

Probably not with an each loop. You'd be better having your click function capture clicks and process an item from the list of items based on a pointer you set. So something like this:

var jsonData = "";
var pointer = 0;
$.getJSON('http://example.com', function(data) {
    jsonData = data;
};
$("#next").click(function() {
    //process item described by pointer
    pointer = pointer + 1;
});

Upvotes: 4

Related Questions