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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:39:46+00:00 2026-05-25T15:39:46+00:00

I am using jQuery load() function to load some pages into container. Here is

  • 0

I am using jQuery load() function to load some pages into container. Here is the code:

$('div.next a').live('click',function() {

    $('.content').load('page/3/ #info','',function(){
        //do something
    });

return false;

});

Everything works just fine but the problem is when I quickly double click the div.next link, from console I see that it loads the page twice because I did a quick double click. I could even make it 3 clicks and it will load it 3 times and show in console smth like that:

GET http://site/page/3/     200     OK  270ms   
GET http://site/page/3/     200     OK  260ms

My question is how to prevent such double clicking and not to let load the target page more then once no matter how many times it was clicked.

Thank you.

  • 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-25T15:39:47+00:00Added an answer on May 25, 2026 at 3:39 pm

    Whatever happened to good ol’ JavaScript? Why are you all trying to figure it out with pure jQuery?

    var hasBeenClicked = false;
    
    $('div.next a').live('click',function() {
    
        if(!hasBeenClicked){
            hasBeenClicked = true;
            $('.content').load('page/3/ #info','',function(){
                //do something
                //If you want it clickable AFTER it loads just uncomment the next line
                //hasBeenClicked = false;
            });
        }
    
        return false;
    });
    

    As a side note, never never never use .live(). Use .delegate instead like:

    var hasBeenClicked = false;
    
    $('div.next').delegate('a','click',function() {
    
        if(!hasBeenClicked){
            hasBeenClicked = true;
            $('.content').load('page/3/ #info','',function(){
                //do something
                //If you want it clickable AFTER it loads just uncomment the next line
                //hasBeenClicked = false;
            });
        }
    
        return false;
    });
    

    Why? Paul Irish explains: http://paulirish.com/2010/on-jquery-live/

    To answer your comment…

    This could happen if you have your delegate function nested inside your AJAX call (.load(), .get(), etc). The div.next has to be on the page for this to work. If div.next isn’t on the page, and this isn’t nested, just do this:

    $('#wrapper').delegate('div.next a','click',function() {
    

    http://api.jquery.com/delegate/

    Delegate needs the selector to be the parent of the dynamically added element. Then, the first parameter of delegate (div.next a in the last example) is the element to look for within the selected element (#wrapper). The wrapper could also be body if it’s not wrapped in any element.

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

Sidebar

Related Questions

I'm using the simple jQuery DIV refresh code. var refreshId = setInterval(function() { $('#refreshdash').load('dashboard.php?cache=');
I'm using JQuery to load the content of an MVC usercontroll: function menuShowModal(a) {
In a simple web page I load some new HTML into a div using
I'm loading some some html into a div through ajax using jquery. Once the
I have a page which loads children pages by using jQuery's .load function... My
I am trying to load some content into a page using Ajax. The html
Hello everyone I got trapped when Im using jquery loading some content into my
I'm writing an app that loads in content via ajax using the jQuery.load function.
After loading a PHP template (using jQuery's load function), this simple script won't make
I'm trying to load fragments of XHTML markup using jQuery's $.fn.load function, but it

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.