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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:50:16+00:00 2026-06-18T11:50:16+00:00

I am writing a script to dynamically create and remove elements, adding the elements

  • 0

I am writing a script to dynamically create and remove elements, adding the elements works fine. But the #removeText function is not firing, I assume something because it was created after the page had finished loading or something. How can I get the #removeText click function to work if it has been dynamically created?

var i = 0;

$('#addText').on('click', function() {
    var div = $("#addText").closest('div').attr('id');

    $("<p><input type=\"text\" id=\"text" + i + "\" placeholder=\"Type something…\"><a href=\"#\" id=\"removeText\">Remove</a></p>").appendTo('#' + div);
});

$('#removeText').on('click', function() {
    console.log(1);
});
  • 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-18T11:50:17+00:00Added an answer on June 18, 2026 at 11:50 am

    If #removeText does not exist in the DOM when you call $("#removeText").on, then nothing gets bound because there is nothing to bind to because it does not exist.

    All is not lost. Use event delegation:

    $(document).on('click', '#removeText', function () {
    

    You should probably do the same with #addText as well. You can delegate to elements that already exist in the DOM too.

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

Sidebar

Related Questions

Writing a script to automatically create an appointment in outlook via javascript. It works
I am writing a script to talk with twitter - everything seems fine apart
I am writing a script that allows users to create teams, send contracts to
I am currently writing a Python script and trying to dynamically generate some arguments.
I'm writing a WIX script. I have a custom-action that adds rows dynamically to
I load some .js dynamically by creating a script tag and writing javascript to
I am writing a PHP script to dynamically resize an image. The image ID
I'm writing script in remote.ini The script looks like on 1:start:{ server some.irc.server server
im writing a script to get services from local and remote machines. I've had
I am writing a script in perl where I use forking and I need

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.