Is there a way to have content update automatically?

After writing this block of code, I discovered that clicking on one of the circles activates it and displays the corresponding content. Now, I am looking for a way to automate this process so that every 5 seconds, a new circle gets activated along with its associated content shown. My goal is to create an endless loop of this activation.

<html>
  <head>
     <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
     <style>
        #timeline{height:460px;width:3px;background-color:#E6E6E6;position:absolute;left:50%;top:55px;}

        a.cirle{width:15px;height:15px;background-color:#E6E6E6;border-radius:50px;position:absolute;}
        a.cirle:hover{background-color:red;}
        a.cirle.active{background-color:red;}

        .contentquestion1{position:absolute;top:35px;margin-left:-7px;left:50%;}
        .contentquestion2{position:absolute;top:225px;margin-left:-7px;left:50%;}
        .contentquestion3{position:absolute;top:425px;margin-left:-7px;left:50%;}

        #contentanswer {position: absolute;left: 50%;top: 200px;margin-left: 50px;}
        #contentanswer1 {position: absolute;left: 50%;top: 200px;margin-left: 50px;display:none;}
        #contentanswer2 {position: absolute;left: 50%;top: 200px;margin-left: 50px;display:none;}
        #contentanswer3 {position: absolute;left: 50%;top: 200px;margin-left: 50px;display:none;}
     </style>
  </head>
  <body>      
     <div id="timeline"></div>
     <script type='text/javascript'>//<![CDATA[
            $(window).load(function(){
            $('[class^="contentquestion"]').on('click', function(e){
                e.preventDefault();
                var numb = this.className.replace('contentquestion', '');
                $('[id^="contentanswer"]').fadeOut(500);
                $('#contentanswer' + numb).fadeIn(500);
            });
            });//]]> 
     </script>
     <script type='text/javascript'>
            $(function() {
               $('a.cirle').click(function() {
                   $('a.cirle').removeClass('active');
                $(this).addClass('active');
               }).eq(1).addClass('active');
            });
     </script>
     <div class="timeline timeline1">
        <div class="contentquestion1"><a class="cirle" href="#"></a></div>
        <div class="contentquestion2"><a class="cirle" href="#"></a></div>
        <div class="contentquestion3"><a class="cirle" href="#"></a></div>
     </div>   

     <div class="new_member_box_display" id="contentanswer">CONTENT 2</div>
     <div id="contentanswer1">CONTENT 1</div>
     <div id="contentanswer2">CONTENT 2</div>
     <div id="contentanswer3">CONTENT 3</div>
  </body>
</html>

Codepen: http://codepen.io/anon/pen/BoWZgY

Answer №1

Here's a handy code snippet to add to your project:

jQuery.fn.shuffle = function () {
          var randomIndex = Math.floor(Math.random() * this.length);
          return jQuery(this[randomIndex]);
      };

      setInterval(function () {
          $('.circle:not(".active")').shuffle().click();
      }, 2000);

Answer №2

If you want to navigate to the next circle in a list, you can achieve this by first finding the index of the currently active circle and then clicking on the next one. By using the % operator, you can create a loop that continues indefinitely.

Check out this example for reference: http://codepen.io/anon/pen/AbCdEfG

setInterval(function(){
  var totalCircles = $("a.cirle").size();
  var currIndex = $("a.cirle.active").index("a.cirle");
  currIndex++;
  $('a.cirle').eq(currIndex % totalCircles).click();
}, 1000); // Modify the time interval as needed (e.g., 5000 = 5 seconds)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Minimize the length of Java code

I am working on implementing a search column in my project and the code provided below is meant to achieve that. However, I have concerns about the code's efficiency as it appears to be quite lengthy. Is there a way to accomplish the same task with fe ...

"Trouble arises when dealing with nested object arrays in Formik and handling changes in a child

I am struggling with passing a value to handleChange in formik validation. To address this issue, I created a component whose quantity is dynamically added based on the number of numChild. My goal is to allow users to click an icon and add any number of sk ...

Cookie Multitree: An Innovative JsTree Solution

Hello everyone, I am currently using jstree and have come across a couple of issues with having multiple trees on the same page. Here are my two problems: 1) I am looking to implement cookies to keep track of which nodes are open in each tree. I attempted ...

Updating component (`App`) during the rendering of another component is not allowed

I have encountered an issue with a react component that I am struggling to resolve. It involves a radial knob control, similar to a slider, and I am trying to achieve two main objectives: Adjust the knob and pass its value up to the parent component for ...

Is there a way to include an edit, delete, details, and create new icon in an @html.actionLink within MVC?

This HTML code is specific to MVC and represents the formatting used: 1. @*@Html.ActionLink("Delete", "Delete", new { id=item.ActivityDepreciationTypeId })*@ 2. @*@Html.ActionLink("Details", "Details", new { id=item.ActivityDepreciationTypeId })*@ ...

Leveraging batchWriteItem with dynamodb

I am trying to utilize batchWriteItem in my DynamoDB to add data to two tables: candidate table and user table. The formatted query is shown below: var user = { userid: usrid, role: 'candidate', password: vucrypt.encryptp ...

The PreparedStatement.setTimestamp method seems to be failing to insert the Timestamp value into the

I am currently developing an account management system where the objective is to save a trial period in the database. The issue I am facing is that every time I try to update the timestamp "2015-10-30 22:55:48" obtained from the jsonObject in a REST servic ...

Tips for styling links in Nuxt/Vue based on specific conditions

Struggling with conditional styling in my Nuxt app. I want to change the background color of the active link based on the current page. Using .nuxt-link-exact-active works for styling the active link, but how can I customize it for each page? The links ar ...

Encountered an error: Unable to access the 'event' property as it is undefined in Laravel 5.3

I'm a beginner with Laravel. Here's my script code that I'm using to retrieve a location in my input field: <script type="text/javascript> google.maps.event.addDomListener(window, 'load', function () { ...

Mesh object circling in the opposite direction of the displayed image

Working on replicating a Flash website using Three.JS and facing difficulty in achieving desired functionality. The goal is to create button images that orbit around the center of the screen, stop when hovered over by the mouse, and open a different locat ...

Splitting a square into four triangles using CSS styling

My current challenge involves creating a square comprised of 4 triangles of equal size, each with hover events. Here is the CSS I'm using to create the triangles: .right, left, .top, .bottom { position: relative; width: 26px; } .right:before ...

Insert an HTML page into a div element

I am having an issue with my angular template. I have a div where I am attempting to load an HTML view file (.html) based on a $watch event, but for some reason, the HTML view is not being loaded into the div. Below is a snippet of my controller code that ...

Guide for displaying SQL data in an HTML table

I am currently working on transferring my SQL data to an HTML format. The code I have so far is not functioning as expected. I attempted to include HTML within my PHP code, and now I am considering if it would be better to do it the other way around (emb ...

Tips for updating the current user's username value in local storage in Angular

https://i.stack.imgur.com/ZA32X.png https://i.stack.imgur.com/iDHZW.png I am facing an issue with updating the local storage of a current User for only username. When I update the username, it's not reflecting in local storage. Even though I can s ...

What are the steps to incorporate swipe functionality into my component?

I've created a carousel using React-slideshow-image, but the issue is that it doesn't support swiping on mobile devices. I would like to implement swipe functionality myself, but I'm not sure how to go about it. Can anyone provide guidance ...

How to properly display an Angular Template expression in an Angular HTML Component Template without any issues?

When writing documentation within an Angular App, is there a way to prevent code from executing and instead display it as regular text? {{ date | date :'short'}} Many sources suggest using a span element to achieve this: <span class="pun"&g ...

Adjust the size of an image based on the smaller dimension utilizing CSS

Allowing users to upload images that are displayed in a square container in the UI presents challenges. The uploaded images can vary in size, aspect ratio, and orientation, but they should always fill the container and be centered. To address this issue, ...

What is the best way to transfer the JWT token from the server to the client using an HTTP header?

I have been searching for an answer on how to pass the JWT Token from the client to the server securely, but I am not satisfied with the explanations I found. Everyone talks about the most secure way to transfer the JWT token using HTTP headers instead of ...

Centering loaders within elements of an unordered list

I am working on a navbar that uses Bootstrap 3 and AngularJS. Within this navbar, I have an unordered list with li elements. Below is a snippet of my navbar: https://i.stack.imgur.com/o75Lp.png This is the code for my navbar: <div class="navbar-head ...

How to seamlessly integrate Redux into your React project using create-react-app?

Is it correct to pass a reducer as props when using a rootreducer? This is the content of my rootReducer.js file: import { combineReducers } from 'redux'; import simpleReducer from './simpleReducer'; import messageReducer from '. ...