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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:13:01+00:00 2026-06-10T02:13:01+00:00

I made a dynamic form with an add button that creates a new division

  • 0

I made a dynamic form with an add button that creates a new division with the clone of the form but has a different ID. However, I also want to have a delete button with each division that removes the division that it is in, including the button itself.

I am familiar with JQuery .remove() method but I am having trouble selecting the division that the button is in.

<div id="attendees">
        <div id="att1" class="attendee">
            <form name="droplist" action="html_form_action.asp" method = "get">
                <fieldset>
                    <legend><span class="legend">Filter</span></legend>
                    <label for="select">Category: </label>
                    <select id="select" size="1"  >
                        <option value=" " selected="selected"> </option>
                        <option value="employees">Number of Employees</option>
                        <option value="hits">Hits on TechCrunch</option>
                        <option value="time_founded">Time Founded</option>
                        <option value="total_money">Total Money</option>
                    </select>

                    <div id='radioContainer' style="display:block;">
                        <input type="radio" id="condition"  name="button" value="more"/> <label for="condition"> > </label></br>
                        <input type="radio" id="condition1"  name="button" value="less"/> <label for="condition1"> < </label>
                    </div>

                    <div id='radioContainerTime' style="display:block;">
                        <input type="radio" id="condition2"  name="button" value="later"/> <label for="condition"> After </label></br>
                        <input type="radio" id="condition3"  name="button" value="earlier"/> <label for="condition1"> Before </label>
                    </div>

                    <div id = "text_box" style="display:block;">
                        <label for="input_value">Amount: </label>
                        <input type="text" id="box" name="input_value" value="textIn" />
                    </div>
                    <button>remove</button>
                </fieldset>
            </form>
        </div>
        <a href="#" class="add">Add more</a>
</div>​

My JavaScript so far is this:

$(function(){
 var template = $('#attendees .attendee:first').clone(),
     attendeesCount = 1;

 var addAttendee = function(){
     attendeesCount++;
     var attendee = template.clone().find(':input').each(function(){
         var newId = this.id.substring(0, this.id.length-1) + attendeesCount;
         $(this).prev().attr('for', newId); // update label for (assume prev sib is label)
         this.name = this.id = newId; // update id and name (assume the same)
     }).end() // back to .attendee
     .attr('id', 'att' + attendeesCount) // update attendee id
     .prependTo('#attendees'); // add to container
 };

 $('.add').click(addAttendee); // attach event
 }); 

$("button").click(function () {
  $this.remove();
});
  • 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-10T02:13:03+00:00Added an answer on June 10, 2026 at 2:13 am

    To delete the <div class="attendee"> that contains the button, you can just use this:

    $("button").click(function () {
         $(this).closest(".attendee").remove();
         return(false);
    });
    

    This looks up the parent chain from the clicked button to find the first part with a class="attendee" and then removes that.


    FYI, I’d strongly suggest putting a class on your delete button because it’s a little dangerous to hook up to ALL buttons in your page.

    To put a class on your delete button, change the HTML to this:

    <button class="deleteButton">remove</button>
    

    And, change the jQuery to this:

    $(".deleteButton").click(function () {
         $(this).closest(".attendee").remove();
         return(false);
    });
    

    The return(false) prevents any default action in the form from occurring based on the click.

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

Sidebar

Related Questions

I have a dynamic form that adds users to the site, made so you
So I have a script that makes dynamic form content and each input has
So I have a script that makes dynamic form content and each input has
so I want to use this JQuery plugin that Stack Overflow has made available
I have made a portlet that uploads a document from a form. I have
I have a dynamic form that can be cloned, using the SheepIt! plugin to
I would like to show a video on a website made of a dynamic
I made a dll in c# but i need to export the functions. Is
I made an iphone app to capture image from camera and to set that
I made an application that passes trough an XML file and extracts the entries

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.