Add class to elements one by one jquery EDITED
<p><strong>2º EDIT</strong>:</p>

<p>thought it was solved but it isn't. when a page is loaded i want to add a class to some elements(on this case is to buttons) and for now my code is:</p>

<pre><code>        $("button").each(function(index){       
            // add the class
            setTimeout(function(){
                $(this).addClass("varrimento");
            }.bind(this),index*5000);
            // remove the class
            setTimeout(function(){
                $(this).removeClass("varrimento");
            }.bind(this),(index+1)*5000); 
        });
</code></pre>

<p>This code add the class "varrimento" for 5 secs to each button one by one but it has 2 problems.</p>

<ul>
<li><p>When i change page and return to the initial page it's like the
setTimeout of the first visit on the page it's still running, so on
the second visit the code of "varrimento" it's added to the buttons
again and they are not one by one like the first visit.</p></li>
<li><p>In some pages, don't know why, it takes too long to adding the class
to the elements. ex: on page "index" right after i visit page, the
class is added immediately to the first button but changing to second
page (code is the same, the only thing that differs is the amount of
buttons) it takes like 15secs to the first button have the class.</p></li>
</ul>

<p>Second day in a row trying to solve this problem but can't figure it out. any help guys?</p>