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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:17:07+00:00 2026-06-18T05:17:07+00:00

I do have a problem to stop executing functions, I’ll try to explain what

  • 0

I do have a problem to stop executing functions, I’ll try to explain what I want to do and how I’m trying to do it.

For example, I bind some event on element a or button and I’d like to user will not click it again, I mean they can click it, but all actions will not be called for some time (say a second).

So, here is some examples:

In html

1st example 
<ul>
   <li><a href="some url" class='button'>Click me</a></li>
   <li><a href="some url" class='button'>Click me</a></li>
   <li><a href="some url" class='button'>Click me</a></li>
</ul>

2nd example somewhere else:
<section id='someid'>
   some info
   some articles - doesn't matter
   <button class='button iLoadComments'>Load more comments</button>
</section>

In JavaScript:

$("ul").on("click","a.button",function(){
   ... here some code or ajax request, whatever
   return false;
});
$("section").on("click","iLoadComments",function(){
   ... some ajax request
   return false;
})

and I’d like to not allow to execute it,
and I want to cover ALL code by one function.

So, what I did: globally I defined a new event listener and add attribute disabled to that element

$("body").on("mousedown", ".button", function(e){
    var $this=$(this);
    if ($this.attr("disabled")) {
        var event = e || window.event;
        if (event.stopPropagation) {
                event.stopPropagation();
        } else {
                event.cancelBubble = true;
        }
        event.preventDefault();
        setTimeout(function () {
           $this.removeAttr("disabled");
        }, 1000); 
        return false;
    }else{
       $this.attr("disabled", true);
       
    }
});

but the problem is delegated function will execute anyway!

Could somebody help please, is there better practise, or way to correct that way?

  • 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-18T05:17:08+00:00Added an answer on June 18, 2026 at 5:17 am
    var click_enabled  = true;
    $("body").on("click",".button",function(){
       if (click_enabled) {
            click_enabled = false;
            setTimeout(function() {
                click_enabled =  true;
            }, 1000);
       } 
       return false;
    });
    
    $("ul").on("click","a.button",function(){
        if (!click_enabled)
            return false;
       //... here some code or ajax request, whatever
    });
    $("section").on("click",".iLoadComments",function(){
        if (!click_enabled)
            return false;
       //... some ajax request
    });
    

    http://jsfiddle.net/EAhK4/

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

Sidebar

Related Questions

I want to implement some functions and variables into Element member of mootools. I
I have a problem trying to stop a process during execution. My process consists
I have problem developing with live555. I already build the lib-files and example projects
I have a problem with time measuring that's really bothering me. I am executing
I have some problems with JavaScript timings..Basically i want it to start timing when
If I have a class delete itself, should its internal methods stop executing? I
I have a curious problem with some javascript. In the following code the browser
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar
I have problem with my query on C, I’m using the oci8 driver. This
I have problem with repopulating form_upload after validation. Other input fields or selectboxes 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.