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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:50:40+00:00 2026-05-31T00:50:40+00:00

It seems this subject is recurring, but sorry, I can’t really find any answer

  • 0

It seems this subject is recurring, but sorry, I can’t really find any answer to my problem.

I’m using jQuery to update a div content with Ajax.
This update is triggered by items inside the updated div.

$(function() {

    $(".add").on('click',function(){
        $("#table").load("displayTable.php");
    });

    // just to see if I can update the DOM...
    $('input').on('click',function(){
        $(this).css("background","red");
    });

});

Html:

    <div id="table">
      <input type="text" />            
      <a class="add">Add</a>
    </div>

As DOM is not updated, jQuery functions only work with the original #table, not the ajax-loaded one.

I’ve not really well understood how to use on(), as I guess this would be the solution to update the listener…

Thanks for your help 🙂

  • 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-31T00:50:41+00:00Added an answer on May 31, 2026 at 12:50 am

    Let’s start by defining a couple of terms. The element where the event handler is bound is called the capturing element. The element where the event originates (so, the element that was clicked) is the originating element.

    These elements do not have to be the same, because events in Javascript bubble, that is to say, all ancestor elements of the originating element are notified of the event. So you can handle the event on any of the ancestor elements. This is called event delegation.

    The on method is a nice way of doing event delegation. The element in the original selection is the capturing element: the event handler will be bound to this element. If this element always exists – i.e. it is not replaced by AJAX – you can be sure that all events will be handled by this handler, even if they originated on elements that don’t exist yet.

    The simplest form of on only has one selector, which is treated as both the originating element and the capturing element:

    $('input').on('click', function() {
    

    The handler is bound to all input elements, and events that originate on input elements are handled by it. However, only input elements that existed when the handler was bound will have the handler bound, so this isn’t much good for you.

    There is another syntax, with an additional selector. This allows you to specify both the element where the handler is bound and also another selector that specifies where it must originate. In this case, #table will always exist, so we can bind to that:

    $('#table').on('click', 'input', function() {
    

    This says, “bind an event handler to #table, but only activate it if the event was a click on an input element”.

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

Sidebar

Related Questions

there seem to be a few posts on this subject but i can't find
It seems this should be easy but I'm having a lot of difficulty using
I went through tons of questions about this subject, but still failed to find
I have seen other posts on this subject, but this seems different. I am
I know this seems like a really subjective question, but from what I'm reading,
It seems that when using a primitive type (string, number) as the this subject
I've checked other threads about this subject, but nothing really answers my exact question.
There seem to be many questions asked about this subject here on stackoverflow, but
Reading the documentation it seems this might not be possible, but it seems that
I've been using socket.io with node.js and came across Nowjs , it seems this

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.