i have this code:
setInterval(function() {
$('.button2').trigger('click');
$('.button3').trigger('click');
}, 5000);
result:
it presses .button2 and .button3 at the same time every 5 seconds. I need something like this – 5 seconds passed press .button2, 5 seconds passed press .button3, need a delay between each button clicks and when .button3 is pressed – again press .button2 (something like a loop).
Any help would be appreciated!
EDIT for flesk:
$(document).ready(function (){
$('.goluboi a').click(function(){
var integer = $(this).attr('rel');
$('.videos .cover').animate({left:-875*(parseInt(integer)-1)}) /*----- Width of div mystuff (here 160) ------ */
$('.goluboi a').each(function(){
$(this).removeClass('active');
if($(this).hasClass('button'+integer)){
$(this).addClass('active')}
});
});
setTimeout(function() {
triggerClick('.button', 0)
}, 5000);
function triggerClick(selector, index) {
var buttons = $(selector);
var mod = index++ % buttons.length;
$(buttons[mod]).trigger('click');
setTimeout(function() {
triggerClick(selector, index);
}, 5000);
}
});
You could do:
EDIT: Answer to your comment below:
Works for any number of buttons, as long as they all have the same class. There’s no need to call them ‘button1’, ‘button2’ and ‘button3’ anyway. That’s what id’s are for.
EDIT2:
If I understand your update correctly, what you want is: