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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:33:04+00:00 2026-06-10T22:33:04+00:00

I am trying to ‘ajaxify’ standard links. I am using the jQuery on() function

  • 0

I am trying to ‘ajaxify’ standard links. I am using the jQuery on() function to intercept the click and retrieve the content dynamically:

$('.nextLink').on("click", function(e) {
    url = $(this).attr( 'href' ).replace( /^#/, '' );
    $.get(url, null, function(response) {
        $('#searchResults').replaceWith(response);
    });
});

This works fine except that the standard link behavior still occurs so I get the content using ajax but then it’s wiped by a full page refresh. I tried returning false from the handler to prevent the normal submit

$('.nextLink').on("click", function(e) {
    ...
    return false;
}

This works however I also have links in the content which is loaded by ajax. My understanding is that jQuery’s on() function should rebind the handlers for content loaded using ajax however it seems adding return false prevents this happening.

So it seems i am in a catch-22 situation, I can either allow the event bubbling to occur which allows ‘on()’ to work correctly however I also get a non-ajax submit, or I can prevent the standard submit but this breaks on()

Can someone tell me the best way to handle this situation?

Many thanks

  • 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-10T22:33:05+00:00Added an answer on June 10, 2026 at 10:33 pm

    …This works fine except that the standard link behavior still occurs so I get the content using ajax but then it’s wiped by a full page refresh…

    Use preventDefault() to stop the default action

    $('.nextLink').on("click", function(e) {
       e.preventDefault();
       ...
    

    to also bind the handler on new added elements you need to use event delegation to capture the click event on a parent element of .nextLink, e.g. with

     $('#searchResults').on("click", ".nextLink", function(e) ...
    

    See on() usage on jQuery docs

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

Sidebar

Related Questions

Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to write a windows speech recognition macro. Written using XML and scripting language
Trying to execute a Powershell cmdlet from a MVC 3 Controller using impersonation but
Trying to understand how EDE works by using it to generate Makefiles for a
trying to import a folder of sprites... also using Zend Framework so my setup
Trying to build a Metro app using Javascript and having issues with IndexedDb. I
Trying to create an SSIS package to process a Datacube. Using SMS 2008, I've
Trying to deploy application using ClickOnce to a webserver running sharepoint. I can publish
Trying to get jquery AutoComplete to return and populate it's dropdown. The input and
Trying to build a CMS for a blog using rails 3. In my routes.rb...

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.