Help with making a jquery script continous loop

Discussion in 'jQuery' started by learnwebsitedesigncom, Jun 22, 2011.

  1. #1
    Hi everyone, how do I make this jquery script loop continously? At the moment it only makes the changes once. The code is shown below.

    HTML:
    <body onload='next();'>
    <p class='active'>
    This is a test
    </p>
    <p>
    This is a test
    </p>
    <p>
    This is a test
    </p>
    </body>
    Code (markup):
    CSS:
    .active { background:red; }
    .bg { background:yellow; }
    Code (markup):
    Jquery:
    function slide(){
     $(document).ready(function(){
      var t = $("p:first");
      
      t.removeClass('active');
      t.next().addClass('bg');
     });
    };
    function next(){
     setInterval('slide()', 1000);
    };
    Code (markup):
    Thank You
     
    learnwebsitedesigncom, Jun 22, 2011 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    try this

    HTML:
    <body onload='slide();'>
    <p class='active'>
    This is a test
    </p>
    <p>
    This is a test
    </p>
    <p>
    This is a test
    </p>
    </body>
    Code (markup):
    CSS:
    .active { background:red; }
    .bg { background:yellow; }
    Code (markup):
    Jquery:
    function slide(){
     $(document).ready(function(){
      var t = $("p:first");
      
      t.removeClass('active');
      t.next().addClass('bg');
      setTimeout('slide()',1000);
     });
    };
    
    Code (markup):
     
    stephan2307, Jun 23, 2011 IP