Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

what's the best way to add a class to the div with a class of post every 4 seconds using jquery?

<div class="34 post">
<img width="311" height="417" src="#" class="#" alt="newspapers" />
<h2><a href="#">Headline News Part 2</a></h2>
<p>testing new content</p>
</div>

<div class="9 post">
<img width="311" height="417" src="#" class="#" alt="newspapers" />
<h2><a href="#">Headline News Part 2</a></h2>
<p>testing new content</p>
</div>

<div class="6 post">
<img width="311" height="417" src="#" class="#" alt="newspapers" />
<h2><a href="#">Headline News Part 2</a></h2>
<p>testing new content</p>
</div>

so i want the first to have a class of "display" then after 4 seconds, i want to remove the class on that one and add it to the second one. and then after 4 more seconds, remove it from the second and add it to the third. when it gets to the end it loops back around.

share|improve this question

closed as off topic by Stephen Harris, Chip Bennett, EAMann Apr 10 '12 at 20:39

Questions on WordPress Development Stack Exchange are expected to relate to WordPress within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Hi Kegan, I've voted to close this as off topic since this question is not related to WordPress (see our faq). stackoverflow.com would probably be the more appropriate site. A mod will probably migrate this question over. –  Stephen Harris Apr 10 '12 at 20:26
    
WOOPSIE. i just moved it over, ill delete it here –  Kegan Quimby Apr 10 '12 at 20:29
    
In the future, please just flag them for moderator attention. We can migrate off-topic questions for you. But since you've already opened one on SO, I'll close this one here. –  EAMann Apr 10 '12 at 20:38

1 Answer 1

up vote 0 down vote accepted
var post_count = $('.post').length,
    current_index = 0;

setInterval(function(){

  $('.post').removeClass('display').eq(current_index).addClass('display');

  current_index++;

  if(current_index > post_count)
    current_index = 0; 

}, 4000);

Wrap it in a jQuery document.ready function :)

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.