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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:20:38+00:00 2026-06-12T18:20:38+00:00

I have a <div> with id=modal generated dynamically with the jQuery load() method: $(‘#modal’).load(‘handlers/word.edit.php’);

  • 0

I have a <div> with id="modal" generated dynamically with the jQuery load() method:

$('#modal').load('handlers/word.edit.php');

word.edit.php contains a few input element, which are loaded into a modal <div>.

Using jQuery’s keyup method I can capture the input values after an event fires, but
when the elements are added dynamically to the modal div, the event no llonger fires when the user enters their text.

Which jQuery method supports handling events triggered by dynamically created elements?

The code for creating the new input elements is:

$('#add').click(function() {
    $('<input id="'+i+'" type="text" name="translations' + i + '"  />')
      .appendTo('#modal');

The code for capturing the user’s values is:

$('input').keyup(function() {
    handler = $(this).val();
    name = $(this).attr('name');

This second code block seems to work for the original elements, but it is not fired by the new dynamically generated 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-06-12T18:20:39+00:00Added an answer on June 12, 2026 at 6:20 pm

    You need to delegate the event to the closest static ancestor element within the page (see also “Understanding Event Delegation”). This simply means, the element where you bind your event handler must already exist at the time the handler is bound, so for dynamically generated elements you must allow the event to bubble up and handle it further up.

    The jQuery .on method is the way to do this (or .delegate for older versions of jQuery.)

    // If version 1.7 or above
    
    $('#modal').on('keyup', 'input', function() {
        handler = $(this).val();
        name = $(this).attr('name');
    });
    

    Or in older versions

    // If version 1.6 or below
    
    // note the selector and event are in a different order than above
    $('#modal').delegate('input', 'keyup', function()
    {
        handler = $(this).val();
        name = $(this).attr('name');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well i have a div tag that i show as a modal dialog this
I have a view with checkboxes, generated dynamically, and a button for chech/unchek all
I have a div generated by a backbone.js view. When the user clicks on
I have the following table dynamically generated from a view. I need to add
I have read a lot about how to validate dynamically generated content in mvc
I have a function that calls .dialog on a dynamically generated element. The code:
I have the following aspx/html page, it uses jquery to display a modal form.
have a menu item which displays a modal div. wish the created div to
I have a Edit View generated by VS 2010 (code below). I don't want
I have the following code in a view: <div class=wrap_select> @Html.DropDownList(dateRange, new SelectList(Model.DateRange, Value,Text),

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.