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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:46:33+00:00 2026-05-14T04:46:33+00:00

I am trying to build a form where users can add a text field

  • 0

I am trying to build a form where users can add a text field by clicking on a “add option” button. They can also remove added fields by a “remove option” link created on the fly by Jquery, along with the text field.

JavaScript:

$(document).ready(function(){
    $("#add_option").click(function()
      {
        var form = $("form");
        var input_field = '<input type="text" />';
        var delete_link = '<a href="#">remove</a>';
        form.append(input_field + delete_link);

        return false;
    });

    $("a").click(function()
    {
        alert('clicked');
        return false;
    });
});

When I click on the “add_option” button, a new text field and the “delete_link” appear. But when clicking on the “delete_link” created by JQuery, the browser follows the link instead of launching a pop-up displaying “clicked”.

How do I hide a dom element after creating it on the fly with JQuery?

  • 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-14T04:46:34+00:00Added an answer on May 14, 2026 at 4:46 am

    I’d use delegate because its uses less bubbling :

    $(document).delegate("a", "click", function(){
     alert('clicked');
    });
    

    EDIT , here is your code you need to change :

    $(document).ready(function(){
           $("#add_option").click(function(){
                   var form = $("form");
                   var input_field = '<input type="text" />';
                   input_field.addClass = "dynamic-texfield";
                   var delete_link = '<a href="#" class="delete-trigger">remove</a>';
                   form.append(input_field + delete_link);
    
                   return false;
               });
    

    Then comes the delegate part :

    $(document).delegate(".delete-trigger", "click", function(){
         alert('ready to delete textfield with class' + $(".dynamic-texfield").attr("class"));
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build a simple HTML text editor in a Windows Form application.
I'm trying to build an admin panel where users can populate the database with
I'm trying to build a Drupal site in which users can input records containing
I'm trying to build a nice contact form, from where a user can send
What I am trying to do is build a form in which the user
I am trying to build a form with multiple autocompleted fields. I am using
I am trying to build a form in HTML that, once submitted, automatically generates
I'm trying to build a form which submits a URL which contains a lon/lat
I am trying to build a registration form. I have a model for all
I'm trying to build a better/more powerful form class for Django. It's working well,

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.