Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7942583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:01:03+00:00 2026-06-04T00:01:03+00:00

BOLD denotes updates. I have an array, steps , whose contents are objects with

  • 0

BOLD denotes updates.

I have an array, steps, whose contents are objects with an action and element associated with them. Like so:

steps = [{action: 'click', element: <jQuery element>}, 
         {action: 'click', element: <jQuery element>}, ., ., N]

I would like to implement a runner, whose job is to run through each element in the array and perform the particular action upon the element. Each step must be performed in serial. So for example, if you have:

 steps = [{action: 'click', element: <jQuery element representing a button>},
          {action: 'click', element: <jQuery element representing an anchor tag>}]

Running, run(steps, timeout), would run through each step. step[0].action would be performed on step[0].element. Since it is possible for step[0] to create the dom element (by means of AJAX) to be interacted with in step[1], the runner needs to wait a particular period(hence, the timeout), polling the dom for the presence of step[1].element.

Here is a rough take at what I have so far:

var run = function() { 
    $.each(steps, function(i, v) { 
        var interval = 25, 
            start = 0, 
            timeout = 3000; 
        var i = setInterval(function(timeout) { 
            start = start + interval; 
            console.log(start); 
            if ($(v).is(':visible')) { 
                v.click(); 
                console.log('clicked', v); 
                clearInterval(i);
            }   
        }, interval);
    }); 
};

Note that in the above example, steps is just an array of jquery objects. It isn’t in the desired format just yet:

steps = [{action: 'click', element: <jQuery element>}, 
         {action: 'click', element: <jQuery element>}, ., ., N]

What is the ‘pattern’ so to say, that I need to follow? Do I need to use deferred objects to take care of this? Is it implemented with a setTimeout, setInterval? Thanks!

Final implementation

var run = function(steps, interval, timeout) {
    var timer,
        time = 0,
        i = 0;

    runSingle(steps[0]);

    function abort() {
        console.log("Run aborted");
    }

    function runSingle(step) {
        timer = setInterval(function() {
            time += interval;
            if ($(step.element).is(':visible') === true) {
                clearInterval(timer);
                time = 0;
                $(step.element).trigger(step.action);
                (i < (steps.length - 1)) && runSingle(steps[++i]);
            } else if (time >= timeout) {
                clearInterval(timer);
                abort();
            }
        }, interval);
        console.log("Performed: ", step.action, "on", step.element) 
        if (i === (steps.length - 1)) console.log("Run successful");
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:01:06+00:00Added an answer on June 4, 2026 at 12:01 am

    Here’s something. I haven’t tested it thoroughly:

    var run = function(steps, interval)
    {
        var timer,
            time = 0, timeout = 10000,
            ciel = steps.length - 1,
            i = 0;
    
        run_single(steps[0]);
    
        function run_single(item)
        {
            timer = setInterval(function()
            {
                var $el = $(item.selector);
    
                time += interval;
    
                if ( $el.length )
                {
                    clearInterval( timer );
                    time = 0;
    
                    $el.trigger( item.action );
    
                    i < ciel && run_single( step[ ++i ] );
                }
                else
                {
                    if ( time >= timeout ) clearInterval( timer );
                }
    
            }, interval);
        }
    };
    
    var steps = [
        {action: 'click', selector: '#first'},
        {action: 'hover', selector: '#second'},
        {action: 'change', selector: '#third'}
        // and so on...
    ];
    
    run(steps, 100);
    

    See it here in action: http://jsfiddle.net/myaeh/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have commands like this: \bold{Foo Bar} \bold{Foo Bars} \bold{Foos Bar} .... \bold{Zoo Cars}
What i want to do is have a bold title on the left with
I have a bold line, followed by a line starting with a period. man
How can I make a label bold in a Django form? The form element
I would like to place my bold text (Thierry) some pixels lower... <div class=editor-field>
I have some simple lists and bold/italic text to format with prawn. How do
I want to add GillSans-Bold font to a UILabel. I have set it in
IS it possilbe to inline code a porperty like Font-bold of control like linkbutton?
Ok so I have this drop down and I want to bold the first
I want to find all bold text in a para and wrap them in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.