I have array of values and i want to set those values as placeholders to my input.
How to achieve this using jQuery.each()
only because i solved my issue with this solution and it works perfectly.
I tried doing this to restart it but it's not working:
if(index==arr.length) index=0;
HTML code:
Values : <input name='input' id='input' />
JS/jQuery code:
var arr = new Array();
for (var i = 0; i <= 5; i++) {
arr.push('Value ' + i);//fill array with values
}
function eachChange(){
var x=0;
$.each(arr, function (index, value) {
x++;
setTimeout(function(){
$('input').attr('placeholder', value);
}, x * 1000);
if(index==arr.length) index=0;
});
}
eachChange();//call function