Question

I found a slider on internet. But it has no autorotate property. I've tried to add autorotate function with setTimeout and click functionbut i couldnt success.

This slider has 4 buttons for each slide. I thought i can use click function of jquery for each buttons with loop or something i dont know. Maybe you have better ideas.

The first a tag class name is tt-current. When you click the second button of slider, the second a tag class name being tt-current. I want click next a tag with using setTimeout function. Every 3 seconds it should be click next a tag.

I hope you guys understand my problem. Any help would be appreciated. Sorry for my bad english by the way.

Html file codes:

<nav>
  //first button
  <a class="tt-current"></a>

  //second button  
  <a class="tt-next"></a>

  //third button
  <a></a>

  //fourth button
  <a></a>
</nav>

My jquery codes:

// I've tried to do like this. The next a tag class name can be tt-next so i can click on it. 

setTimeout(function () {
    document.getElementByClass('tt-next').click();               
, 3000);
Was it helpful?

Solution

Also note that there is no method called as getElementByClass , the correct method name is document.getElementsByClassName and this method will return an array so you need to use:

setTimeout(function () {
    document.getElementsByClassName('tt-next')[0].click();               
, 3000);

You can apply jQuery using:

setTimeout(function () {
    $('.tt-next').click();               
, 3000);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top