javascript - Delay after each for loop iteration -


In my MVC project, I have crossed a list of users in my view, and within this view I Repeat through and create an anchor tag for each user It would be possible to add delay after each anchor tag? Here's my junkie:

  desk function.propitip.in = function () {var self = this; Various elements; This.allData = @ Html.Raw (@JsonConvert.SerializeObject (Model.AllDeskData)); (Var i = 0; i & lt; this.allData.length; i ++) {element = $ ("& lt; a href = '#' class = 'deskbutton tooltip fancybox' title = '" + this .all data [i] .departmentName + "'& gt; & Lt; / a & gt; "); $ (Element) .css ({"top": this.allData [i] .DeskYCoord, "left": this.allData [i]. DeskXCoord}). Attachments ("map"). Show ('normal') .delay (3000); $ (Element) .on ('click', function () {var user = $ (this) .attr ("data-name"); $ .ajax ({url: "/ home / getUserData", type: "GET ", Data: {user: user}, success: function (data) {$ (" .user-data .name "). Text (data.displayName);}});}); } $ ('. Tooltip'). Tooltipster (); $ ('Search-user'). Key (function () {self.search ();}); };  

I have to be created and tagged in the first tag, then the second delay, then the next anchor tag will be added, is it possible? Any help would be appreciated

You can try the code below to write all code inside SetTimeout which You want to under the loop. It will be called after 1 second for (var i = 0; i & lt; this.allData.length; i ++) {(function (i, self) {setTimeout ( Function () {// all loop codes here // use self.allData}, 1000);} (I, myself)); }


Comments