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

  • Home
  • SEARCH
  • 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 811493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:03:15+00:00 2026-05-15T01:03:15+00:00

I’m trying to make a jQuery plugin that executes a method on a timer.

  • 0

I’m trying to make a jQuery plugin that executes a method on a timer. I’d like it to work on multiple elements on a page independently. I’ve reached a point where the timer executes for each element, but the method called in the setTimeout seems to only know about the last instance of the plugin.

I know I’m doing something fundamentally stupid here, but I’m danged if I know what. I know stuff like this has been asked 8 million times on here before, but I’ve not managed to find an answer that relates to my specific problem.

Here’s a script that demonstrates the structure of what I’m doing.

<html>
<head>
<script type="text/javascript" src="assets/jquery.min.js"></script>
<script type="text/javascript">
var crap = 0;
(function($) 
{
    jQuery.fn.pants = function(options) {
        var trousers = {
            id: null,
            current: 0,
            waitTimeMs: 1000,

            begin: function() {
                var d = new Date();
                this.id = crap++;
                console.log(this.id);
                // do a bunch of stuff
                window.setTimeout(function(self) {return function() {self.next();}}(this), this.waitTimeMs);
            },

            next: function() {
                this.current ++;
                console.log(this.id);
                window.setTimeout(function(self) {return function() {self.next();}}(this), this.waitTimeMs);
            },
        };

        options = options || {};
        $.extend(trousers, options);

        this.each(function(index, element) {
            trousers.begin();
        });

        return this;
    };
}
)(jQuery);
jQuery(document).ready(function() {
    jQuery("div.wahey").pants();
});
</script>
</head>
<body>
<div class="wahey"></div>
<div class="wahey"></div>
</body>
</html>

The output I get is this:

0
1
1
1
1
1

The output I expect to get is this:

0
1
0
1
0
1
  • 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-05-15T01:03:15+00:00Added an answer on May 15, 2026 at 1:03 am

    It could be that you’re using ‘this’ which is browser specific and doesn’t always point to what you want it to point to. This belongs to the owner of the function, not the object of the function.

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

Sidebar

Ask A Question

Stats

  • Questions 488k
  • Answers 488k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Me.pleaseWaitFrm.Close() That's an illegal call, you are not allowed to… May 16, 2026 at 8:37 am
  • Editorial Team
    Editorial Team added an answer I'm starting to work with Maven but am not yet… May 16, 2026 at 8:37 am
  • Editorial Team
    Editorial Team added an answer You're writing a query and then asking that query to… May 16, 2026 at 8:37 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a JSP page retrieving data and when single or double quotes are

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.