Search code examples
javascriptdomtriggersclickmuse

Trigger mouse click on a button each 5 seconds


How to trigger a mouse click on the element (slider "next" button) each X seconds?

I have built a website in Adobe Muse, but the slider widget doesn’t have an auto play function, and I’m trying to make the next button click each 5 seconds to simulate autoplay. I’ve found the class for the button

<div class="fp-controlArrow fp-next"></div>

maybe there is even a chance to trigger clicking it somehow? Thanks


Solution

  • I had to specify both classes to trigger the button and use a bit more difficult command. This worked:

    var interval = setInterval(function() {
    
    document.querySelector('.fp-controlArrow.fp-next').click();
    
    
    }, 5000);
    

    Now I have additional question: is it possible to stop clicking after user will click either back or next button with a mouse?

    As a half-measure I’ve set it to stop at about a time it returns to the first slide but it would be much better to stop it after user clicks any of the button...

    var interval = setInterval(function() {
    
    document.querySelector('.fp-controlArrow.fp-next').click();
    
    
    }, 7000);
    
    setTimeout(function( ) { clearInterval( interval ); }, 44000);
    

    Thanks