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

  • Home
  • SEARCH
  • 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 7556635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:54:32+00:00 2026-05-30T11:54:32+00:00

I load some html using AJAX, this works fine, one of the bits that

  • 0

I load some html using AJAX, this works fine, one of the bits that loads is a contact form which I am trying to intercept the submit event using

$(document).ready(function() {    
    $('contact_form').submit(function() {
        return false;
    });    
});

The above javascript is loaded with the initial page load.

However, when I visit the page and submit the form it follows its default path and follows the regular submit (which works but it is my non-javascript compatability route that I want most users not to follow). I have tried testing .click() events on bits of the page that are initially loaded and similar bits that are loaded using AJAX, the result being that only the elements that were initially loaded with the page execute the .click() event.

I’m guessing that it is the fact that I load the jQuery code before adding the elements to the DOM (I have some <script> tags that load with the initial page load) and this is not regestering the listeners propperly (wild guess, I actually don’t really have a clue).

Am I correct in my assumption? And what is the best fix?

  • 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-30T11:54:33+00:00Added an answer on May 30, 2026 at 11:54 am

    First of all contact_form isn’t a valid selector, as it’s looking for a <contact_form> element. It should be #contact_form to select by id, or .contact_form to select by class.

    Secondly your assumption about the event handlers is correct, the shortcut event handlers (click, submit etc.) only work on elements available in the DOM on page load.

    If the element is appended to the DOM after page load (eg. via AJAX) you need to use delegate() or on() (in jQ1.7+) to add events to that element:

    $('body').delegate("#contact_form", "submit", function() {
        return false;
    )};
    

    Or:

    $('body').on("submit", "#contact_form", function() {
        return false;
    )};
    

    I have used body as the parent selector here, but you should use the closest static element (that is one that is available in the DOM on page load) to the one you are placing the event on.

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

Sidebar

Related Questions

Im trying to load a page I created using ajax, which loads fine and
I'm using the .load() function to load a section of html that has some
I load up some HTML using $.get or $.ajax . In the debugger for
I have dialog created like this $('#add_error').click(function(e) { $('<div>') .load('/someaction/format/html/') .dialog({ title: 'Some title',
I'm trying to load some stuff using AJAX when a user clicks a link,
I desperately need some help on this one. I've created a <script> that closely
I'm loading some some html into a div through ajax using jquery. Once the
I would like to load some content using AJAX and Shadowbox Basically I would
I have some pretty basic Javascript here which works just fine in Firefox but
I am trying to load html asynchronously using jQuery ajax function. But I for

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.