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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:52:40+00:00 2026-05-15T04:52:40+00:00

Some template written using jquery is as follows . it is not working .

  • 0

Some template written using jquery is as follows . it is not working . Any suggestions to use jquery efficiently .

<html>  
<head>  
<script type="text/javascript" src="/jquerycall/"></script>  
<script type="text/javascript">  
    $(document).ready(function()  
    {  
        self.setInterval("clock()",1000);  
        $("button").click(function()  
        {  
            clock;  
        });  
        function clock()  
        {  
            clock();  
            time=new Date();  
            var s = "<p>" + time + "</p>";  
            $(s).appendTo("div");  
        }
    });  
</script>  
</head>  
<body>  
<form method="post">  
<button type="button">Click Me</button>  
<div id="someid"></div>  
</form>  
</body>  
</html>
  • 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-15T04:52:41+00:00Added an answer on May 15, 2026 at 4:52 am
    function clock()   
    {   
       //clock(); /* Remove this recursive call or you'll just get an infinite loop */
       var current = new Date(); /* Make sure to use var on variables */
       var s = "<p>" + current + "</p>";
       $('#someId').html(s); /* Assuming you want to set 'someId' to 's', not try and append all things that match s to every div */
    } 
    
    var clockStarted = false;
    $("button").click(function()   
    {   
       if (!clockStarted) /* You only need to set the clock to start once */
          setInterval(clock, 1000);  /* You only want the interval to start after you've clicked the button and you don't need 'self'. */
       clockStarted = true;
    
       //clock(); /* Said 'clock;' before */   
    });  
    

    To summarise:

    1. When you call a function, you need to call it with parentheses and optionally parameters (e.g. functionName(); instead of functionName). This applies to all JavaScript.

    2. Imagine there is one little gnome happily running through your code. When he gets to a line he reads it and does it. So let’s say you’ve called clock(). He gets there and goes “what now? Oh, I have to go to clock()”. So he goes to clock(). He gets there and goes “what now?” Oh, I have to go to clock()”. See the pattern? He’s going to keep doing this forever, but he never actually gets a chance to do the things that you want clock() to do, because the first thing he sees as soon as he reaches clock() is that he needs to go to clock(). This is called infinite recursion. What you really wanted was to say “every so often I want a little gnome to go to clock() and do the things in there” which is what setInterval does.

    3. $(s).appendTo(‘div’) selects all things that match ‘s’ (which will be nothing) and appends them to all things that match ‘div’ (which is every div). Instead, you want to select the div with ‘someId’: “$(‘#someId’)”, and append ‘s’ to that: “.append(s);”. If you don’t want to append but instead replace, you will want to use “.html” not “.append”.

    Edits

    • Includes edits as per request.
    • Includes the fixes to ‘setInterval’ and ‘var time’ which slipped past me as per Anurag’s answer. I’m not trying to take credit for these fixes, but just wanted to include as part of a comprehensive answer given the other changes to meet the OP’s comment.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

iam using jquery and want to do below written //this is a template <div
I am loading some template files into my application using require.js like so: define(function(require)
I am using System.IO.FIle.ReadAllText() to get the contents of some template files that I
I have a web application where the masterPage/template contains some static HTML that never
I have a big chunk of HTML which is a template for some data
I've written some code using lambda on vc2010. The simplified structure of code is
I have written a runtime-created dialog class that doesn't use any resource files based
I have a some html being generated by JQuery on a Share Point page.
I've written an installer using NSIS and I need it to install some files
I'm trying to wrap content with some static HTML in MVC and I'm not

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.