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 5987549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:49:52+00:00 2026-05-22T22:49:52+00:00

i am calling a jQuery plugin every 5 seconds with the following code var

  • 0

i am calling a jQuery plugin every 5 seconds with the following code

    var now = new Date();

    setInterval('$("#id").myplugin(now)', 1000);

The Plugin looks like this so far:

    (function( $ ){
    $.fn.myplugin = function(now) {
        return this.each(function() {
            alert(now.getTime());
        });
    }
   })( jQuery );

However I get the error:

Uncaught ReferenceError: now is not defined
plugins.js:30 Uncaught TypeError: Cannot call method ‘getTime’ of undefined

So it looks as if the now time object doenst get passed to the plugin function and is not even defined in the setInterval method. I could probably call var now = new Date(); every time in the plugin function … but I want to know, why it doenst work like that and how to make it work ;). thx alot.

  • 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-22T22:49:53+00:00Added an answer on May 22, 2026 at 10:49 pm

    Use a function like this:

    var now = new Date();
    
    setInterval(function() {
        $("#id").myplugin(now);
    }, 1000);
    

    This way, the so-called scope of now is set to the function in which you call setInterval. Otherwise, it is just the global object (window) you’re referring to, which doesn’t have a now.

    Secondly, passing a string works like eval(), which is unsafe and slow: Why is eval unsafe in javascript?.

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

Sidebar

Related Questions

Say I have the following jQuery plugin: $.fn.myPlugin = function () { //plugin code
I'm using jQuery autocomplete plugin from jQuery website calling the controller url which return
Using the following JQuery/AJAX function I'm calling a partial view when an option is
I essentially have the same goal as in this question: Calling a jQuery plugin
Does anybody know of a jQuery plugin that will allow for what I'm calling
In an aspx page I am calling a jquery plugin for two listboxes as
I'm trying to use a jQuery plugin, the HighCharts, calling the series from a
I have the following jQuery extension: (function ($) { //jQuery plugin extension jQuery.fn.rotate =
I'm getting the following error when trying to use JQuery with the JqSOAPClient plugin:
NOTE: I have now created a jQuery plugin which is my attempt of a

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.