-4

I have this function, $('.trigger-list li ').addClass('animate');

I have a list with 5 list items. When i fire this code. Every second one list item must get the classe animate. How can i set a interval on this?

Thanks

Mike Vierwind
  • 1,482
  • 4
  • 23
  • 44
  • duplicate: http://stackoverflow.com/questions/6081443/run-a-function-in-time-interval-in-jquery?rq=1 – Black Sheep Mar 28 '14 at 16:41
  • What exactly do you expect to happen every second? – Beauvais Mar 28 '14 at 16:42
  • possible duplicate of [JavaScript - jQuery interval](http://stackoverflow.com/questions/7546565/javascript-jquery-interval) – morten.c Mar 28 '14 at 16:42
  • 1
    Re-read your question, is it clear for you? So each second one and only one element must get class animate, other should have class removed, is it this or what? Couldn't you improve your question??? – A. Wolff Mar 28 '14 at 16:51

2 Answers2

2

Try this:

setInterval(function() {
  $('.trigger-list li ').addClass('animate');
}, 2000);
pj013
  • 1,393
  • 1
  • 10
  • 28
0

try using the jQuery :odd selector https://api.jquery.com/odd-selector/

$('.trigger-list li:odd ').addClass('animate');
andrew
  • 9,313
  • 7
  • 30
  • 61
  • Why the downvotes? OP's question is ambiguous and this seems like a valid answer. –  Mar 28 '14 at 16:45
  • I actually didn't downvote this but why do you think this would be the solution? The requester did not specify every second row to be animated – Beauvais Mar 28 '14 at 16:45
  • Thats actually what I thought he was asking. – fny Mar 28 '14 at 16:45
  • 1
    grammar makes all the difference 'Every second, one..' vs 'Every second one...' – andrew Mar 28 '14 at 16:46