javascript - How to run through a function again once it reaches the end? -
how run through loop again once reaches last value in array?
i run function init()
again once completed because more dom elements myelement
ajaxed in once have been clicked on.
i have tried running init
function after settimeout
doesnt work , tried checking last element on array btn.length -1
still doesnt work.
function dosettimeout(index, btn) { settimeout(function() { jquery(btn[index]).click(); }, index * 1500); //init(); } function init() { var btn = [].slice.call(document.queryselectorall('.myelement')); var index; (index = 0; index < btn.length; index++) { dosettimeout(index, btn) } } init();
does work?
function init() { var btn = [].slice.call(document.queryselectorall('.myelement')); var index = 0; function click() { settimeout(function() { if(index < btn.length) { jquery(btn[index++]).click(); click(); } else { init(); } }, 1500); } click(); }
Comments
Post a Comment