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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:30:48+00:00 2026-06-03T05:30:48+00:00

In my jQuery, I have a button that is used to create the remove

  • 0

In my jQuery, I have a button that is used to create the remove button:

$("#add").click(function() {
    var fieldWrapper = $("<div class=\"fieldwrapper\" id=\"field" + intId + "\"/>");
    var removeButton = $("<input type=\"button\" id=\"remove\" class=\"btn\" value=\"Remove\" />");
    removeButton.click(function() {
        $(this).parent().remove();
    });

    fieldWrapper.append(removeButton);
});

However, when I add a remove button manually using the PHP instead of jQuery

<div class='fieldwrapper' id=<? echo "field".$counter ?>
    <input type='button' id='remove' class='btn' value='Remove'>
</div>

I have checked if the fieldwrapper id is not overlapped, so why does it not work? Thank you.

Updated:

$(document).ready(function() {
    $("#config").validate();

    $('#id').click(function() {
        $(this).parent().remove();
    });

    $("#add").click(function() {
        var intId = $("#configField div").length + 1;
        var label = $("<label>Field Name:</label>");
        var labelType = $("<label>Field Type:</label>");
        var labelReq = $("<label>Require:</label>");
        var labelTag = $("<label>Tag:</label>");
        var fieldWrapper = $("<div class=\"fieldwrapper\" id=\"field" + intId + "\"/>");
        var fName = $("<input type=\"text\" name=\"Name" + intId + "\" class=\"required\" />");
        var fTag = $("<input type=\"text\" name=\"Tag" + intId + "\" class=\"required\" />");
        var fReq = $("<select  class=\"required\" name=\"Req" + intId + "\" ><option selected=\"\" value=\"\">Please Select</option><option value=\"1\">Yes</option><option value=\"0\">No</option></select>");
        var fType = $("<select  class=\"required\" name=\"Type" + intId + "\"  ><option selected=\"\" value=\"\">Please Select</option><option value=\"txt\">Text</option><option value=\"int\">Numbers</option><option value=\"bool\">Boolean</option></select>");
        var removeButton = $("<input type=\"button\" id=\"remove\" class=\"btn remove\" value=\"Remove\" />");

        fieldWrapper.append('<br>');
        fieldWrapper.append(label);
        fieldWrapper.append(fName);
        fieldWrapper.append('<br>');
        fieldWrapper.append(labelType);
        fieldWrapper.append(fType);
        fieldWrapper.append('<br>');
        fieldWrapper.append(labelReq);
        fieldWrapper.append(fReq);
        fieldWrapper.append('<br>');
        fieldWrapper.append(labelTag);
        fieldWrapper.append(fTag);
        fieldWrapper.append('<br>');
        fieldWrapper.append(removeButton);
        $("#configField").append(fieldWrapper);
    });

    $('.remove').on('click', function() {
        $(this).parent().remove();
    });
});

PHP:

<div class='fieldwrapper' id=<? echo "field".$counter ?>
    <input type='button' id='remove' class='btn remove' value='Remove'>
</div>
  • 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-03T05:30:50+00:00Added an answer on June 3, 2026 at 5:30 am

    You’re only initiating the remove button functionality after clicking “#add”. By declaring it apart from the internal function, and specifying “delegate(‘click’, ” you will ensure that every .remove element will always delete its parent

    $("#add").click(function() {
    
        var fieldWrapper = $("<div class=\"fieldwrapper\" id=\"field" + intId + "\"/>");
        var removeButton = $("<input type=\"button\" id=\"remove\" class=\"btn remove\" value=\"Remove\" />");
    
        fieldWrapper.append(removeButton);
    });
    
    
    $('.remove').delegate('click', function() {
        $(this).parent().remove();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following home-grown jquery plugin: (function($) { $.fn.defaultButton = function(button) { var
I have a button that does not work in jquery. A button is passed
I'm trying to use $(button).button(); but jquery-ui-1.8.16.custom.min.js used by SlickGrid doesn't have the button
I have a form that I want to be used to add entries. Once
I have a button class that I wrote in CSS. It essentially displays block,
I have to create the Jquery Grid that have check boxes and drop down.
I created some widgets with jQuery UI and I notice that buttons have a
I have a Jquery Mobile page. In my header I have a button to
I am using jquery mobile... I have a button (data-role=button) which calls a javascript
I have a problem selecting a checked radio button with jquery. The radio buttons

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.