Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
33
rated 0 times [  36] [ 3]  / answers: 1 / hits: 17862  / 12 Years ago, tue, april 10, 2012, 12:00:00

for some reason, this isn't adding and removing a new class on elements with the class of post, every 4 seconds. jquery loads correctly, as does this. chrome shows no errors with the code.



$(document).ready(function(){
$('.post').addClass('display').delay(4000).removeClass('display');
});

More From » jquery

 Answers
20

Since you listed you want this to happen every 4 seconds you can simply use setInterval()



var $post = $(.post);
setInterval(function(){
$post.toggleClass(display);
}, 4000);


Note, the selector is cached in $post to minimize the number of times the DOM needs queried on each interval.



Example on jsfiddle


[#86329] Monday, April 9, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
frankiefredyr

Total Points: 555
Total Questions: 108
Total Answers: 94

Location: Egypt
Member since Tue, May 3, 2022
2 Years ago
;