Search code examples
javascriptjquerytogglepageload

How to make a timed automatic content toggle?


Hi here's the goal: to create an automatic bit of content that toggles open after a set period of time automatically on page load. I don't want any button or text to control the toggle, and it would be even better if it toggled back into nothingness after a set time!

I hope that makes sense! Thanks.


Solution

  • setInterval will accomplish your goals:

    setInterval(functionName, milliseconds);
    

    Example function:

    function functionName() {
        $('.toggle-containers').toggleClass('visible');
    }
    

    Little demo