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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:37:53+00:00 2026-05-27T09:37:53+00:00

When I load jQuery dynamically with AJAX, elements with existing events fire multiple times.

  • 0

When I load jQuery dynamically with AJAX, elements with existing events fire multiple times.

Basically I have one file called ‘myjs.js’ which hold All my jQuery and is included when the page is loaded therefore setting up events and such for elements.

Now when a user triggers an event like posting a new comment, it sends off (via Ajax) the comment, then it returns a page with the new comment, edit comment, reply etc. Obviously when myjs.js was first loaded it didn’t create any events for the newly loaded elements. Therefore I include myjs.js in the page returned with AJAX.

As the myjs.js has already been loaded with the page, when the Ajax page is returned with myjs.js included, it adds another event to the elements that have already been loaded with the page.

I have already tried

$('*').unbind();

But this caused some strange effects.

So any ideas on loading jQuery dynamically while not affecting any events which already exist for elements?

  • 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-27T09:37:53+00:00Added an answer on May 27, 2026 at 9:37 am

    Without seeing the jQuery code, I suspect that the selectors being used to bind behaviour are too generic so as you have discovered, all existing elements plus the newly loaded elements are matched each time:

    You could use more specific binding in the JavaScript returned in the AJAX response to add behaviour only to the newly loaded elements.

    However, returning the same JavaScript for each AJAX request is inefficient as the browser cannot cache. Ideally you should try and load the JavaScript on the main page once and then rely on jQuery to do .live() binding automatically for the newly loaded elements. This is also known as event delegation – .delegate()

    Note that as of jQuery 1.7 these methods have been deprecated in favour of a more concise event binding infrastructure – the .on()

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

Sidebar

Related Questions

So I have a system using jQuery AJAX to load the content dynamically. I
When trying to dynamically load a Javascript file using jQuery I keep getting a
I have an existing HTML form that I'm trying to update to use jQuery.load().
I have a jQuery AJAX data grid that loads a list of elements from
I have a div into which I am loading data dynamically by ajax, jquery.
While I was trying to refresh page contents dynamically using Ajax/JQuery, I have learned
I have multiple asp:button that I created dynamically with jQuery. For each of them,
I want to dynamically load JS file using AJAX and execute it. I am
i have a web page that i want to load dynamically (ajax) into a
I have a simple webpage that uses the jquery template plugin to dynamically load

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.