title: jQuery setInterval on slider advance button
body: <p>I am trying to do a slider and having some problems about it.As you can see I have a #timer button, when you clicked the button, it advances the next slide, there is no problem with it.</p>
  
  <p>But I want it to click itself so I am trying to use setInterval but can't do it. Also there is no problem about triggering first click on navitem, but can't setInterval on that button.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(window).load(function() {
      $('.slideritem p').stop(true).show(1000);
  });
  
  $(document).ready(function() {
      $('.slideritem').hide();
      $('.slideritem:first').fadeIn(1000);
  
      $('.navitem').click(function () {
          var index = $('.navitem').index(this)
          var indexlast = $('.navitem').index(this) + 1
          $('.slideritem').hide();
          $('.slideritem:nth-child(' + indexlast + ')').stop(true).fadeIn(1000);
          $('.navitem img ').removeClass('current');
          $('.navitem:nth-child(' + indexlast + ') img ').addClass('current');
  
          $('#timer').click(function () {
              index++$('.slideritem').hide();
              $('.slideritem').eq(index).fadeIn(1000);
              $('.navitem img').removeClass('current');
              $('.navitem img').eq(index).addClass('current');
  
              if (index == 3) {
                  index = -1
              }
          });
      });
  
      $('.navitem:first').trigger('click');
      setInterval($('#timer').trigger('click'), 1500);
  });    
  &lt;/script&gt; 
  </code></pre>