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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:03:17+00:00 2026-06-15T12:03:17+00:00

I am using Backbone here, but I’ve also experienced this issue with non-Backbone sites

  • 0

I am using Backbone here, but I’ve also experienced this issue with non-Backbone sites as well.

Essentially, my issue is that I define in one javascript file, base.js, a number of ‘global’ jquery functions. Then, I load new elements and append them to the page using Backbone, AJAX, or whichever asynchronous call you like. This works great, except the new objects don’t seem to be linked to the jQuery events I declared on pageload. (Sorry for the layman language here – often I am a newbie at proper wording)

For example, let’s say I declare in a js file loaded on pageload:

 $('.element').hover(function(){alert('hi world')});

But then I append a new element after pageload, then this hover won’t work.

Can anyone explain:

  1. Why this is?
  2. Whether I can force a new appended element to work with/listen to current events already declared?

I suspect (2) may not be possible (that I have to rewrite the events after appending), but am interested to know if there is some sort of solution.

  • 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-15T12:03:19+00:00Added an answer on June 15, 2026 at 12:03 pm

    Why this is?

    Because when the event binding code is executed, elements that do not exist in the DOM already will not be affected (how could they be? They don’t exist yet!) The “normal” event binding methods (e.g. .click() or .change()) will attach a copy of the event handler function to every element in the matched set.

    I can force a new appended element to work with/listen to current events already declared?

    You can indeed, by delegating the event handler higher up the DOM tree. Since most DOM events bubble up the tree from the element on which they originate, this works well. With jQuery, you can use the .on() (jQuery 1.7+ – for older versions use .delegate() instead) method to do this:

    $("#someCommonAncestor").on("someEvent", ".element", function () {
        // Do stuff
    });
    

    The element on which you call .on() must exist in the DOM at the time the code runs. When the event bubbles up far enough to reach whatever #someCommonAncestor may be, jQuery will check to see if the target element matched the selector you passed to .on(). If it does, it will execute the event handler. If it doesn’t, the event will continue bubbling to the root of the document and not trigger any handler.

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

Sidebar

Related Questions

I am using backbone validate function but it gives this error again Uncaught TypeError:
I'm using backbone for an app that I'm building. In this app, I have
I am using backbone.js here is my scenario Lets say I have a view
I am using the backbone-boilerplate, which you can find here . I was wondering
I'm using Rails. I just installed the backbone-rails gem and followed the instructions here
I am using the backbone boilerplate here https://github.com/tbranyen/backbone-boilerplate I do development in static html/js
I am using backbone.js, and trying to fetch some json from twitter, but it
I am learning backbone routes. I just built a small app using backbone. But
I am using C++ as the app backbone and Objective-C for the GUI, that's
Using backbone.js, here is a quick test to demonstrate the problem I am facing

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.