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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:07:02+00:00 2026-06-01T07:07:02+00:00

I am writing a jQuery plugin that manipulates the value of an input field

  • 0

I am writing a jQuery plugin that manipulates the value of an input field at the press of a button.

What I have so far is the ability to control the value by clicking the button, as well as to continually increase it if the user holds the button pressed.
Simplified, the script is something like this:

var element = $('#test-input');
var interval;

$('#test-up-button').on({
    mousedown : function(e) {
        element.val(parseInt(element.val()) + 1);

        //Wait 400ms, than do the interval

        interval = window.setInterval(function() {
            element.val(parseInt(element.val()) + 1);
        }, 200);      
        e.preventDefault();        
    },
    mouseup : function() {
        window.clearInterval(interval);
    }
});

(You can also see a working version here: http://jsfiddle.net/Husar/Hxhsh/#base )

However, as you can see in the comment, I also want when the mousedown event happens, after the initial increase of the value, the interval function to be delayed for 400ms, and only than to execute.

So that you press the button, value goes + 1, you hold the button a bit, and than the intervals start to roll.

  • 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-01T07:07:04+00:00Added an answer on June 1, 2026 at 7:07 am

    Wrap the setInterval in a setTimeout. And, like interval, keep and clear a timeout value:

    var interval, timeout;
    
    // ...
    
        timeout = window.setTimeout(function () {
            interval = window.setInterval(function() {
                element.val(parseInt(element.val()) + 1);
            }, 200);      
        }, 400);
    
    // ...
    
        window.clearTimeout(timeout);
        window.clearInterval(interval);
    

    http://jsfiddle.net/coiscir/jUSg8/

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

Sidebar

Related Questions

I'm writing a jquery-plugin, that changes a css-value of certain elements on certain user-actions.
I am looking at writing a jquery plugin that takes a number of input
I'm currently writing a JQuery plugin that loads colors from a JSON web service
I'm playing around with writing a jQuery plugin that uses an attribute to define
I'm writing a simple jQuery plugin that will interface with a JSON object/array. I
When writing a new jQuery plugin is there a straightforward way of checking that
I am writing a simple GreaseMonkey script that has a jQuery plugin called hoverIntent
I am writing a jquery plugin that gets a table and allow to change
I'm writing a jQuery plugin that has a couple of callbacks, and am at
I'm writing a jQuery UI plugin. Inside that plugin, when an action occurs, I'm

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.