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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:42:45+00:00 2026-05-15T22:42:45+00:00

I can generate the controls but can’t remove them. I’m trying to add a

  • 0

I can generate the controls but can’t remove them. I’m trying to add a ‘Link’ which will call a function to remove dynamically created control. The control and link are next to each other. Here’s the Java script and mark-up to create the control:

<script type="text/javascript">
        $(function() { // when document has loaded

            //   <input id="File1" type="file" runat="server" size="60" />

            var i = $('input').size() + 1; // check how many input exists on the document and add 1 for the add command to work


            $('a#add').click(function() { // when you click the add link
                $('<p><input type="file" id="' + i + '" name="' + 'dynamic:' + i + '" /> <a href="#" id="' + 're' + i + ' " onclick="removeControl("' + '\'#' + i + '\''+ '")">+</a></p>').appendTo('body'); // append (add) a new input to the document.

                // if you have the input inside a form, change body to form in the appendTo
                i++; //after the click i will be i = 3 if you click again i will be i = 4s
            });

            function removeControl(controlId) {

                $(controlId).remove();
            }


        }); </script>


   <div>
        <a href="#" id="add">Add</a>

<br />


<p><input type="file" id="1" /></p>

    </div>

The script to create the Link to remove the control is not working. The onClick attribute is not mark-up correctly when I use Firebug to see the source.

<a href="#" id="' + 're' + i + ' " onclick="removeControl("' + '\'#' + i + '\''+ '")">+</a>

I just wanna add a Link to remove the generated control and the link itself.

Thank you.

  • 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-15T22:42:46+00:00Added an answer on May 15, 2026 at 10:42 pm

    If you want to remove an element from the Dom which was included via javascript you need to attach or rebind an event handler.

    $('a.remove').live('click', function() {
      // Stuff to remove
    });
    

    Working solution:

    <script type="text/javascript">
        $(function() {
           
            // Init counter
            var counter = 0;
            
            // Add Elements
            $('#add').click(function() {
    
                counter++ // Increment counter
    
                var add_input = '<p><input type="file" />';
                var add_link = '<a href="#" class="remove">Remove</a>';
    
                // Append Elements if counter smaller 4
                if (counter <= 4) {
                    $('body').append('<p>' + add_input + add_link + '</p>');
                }
                return counter;
             });
    
             // Remove Elements
             $('.remove').live('click', function() {
                 counter--; // Decrement counter
                 $(this).parent('p').remove();
             });
         });
    </script>
    
    <a href="#" id="add">Add</a>
    

    FYI-> Always reduce dom inserts to a minimum.

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

Sidebar

Related Questions

I'm looking for a tool which can generate a Makefile for a C/C++ project
I am trying to generate a RTF document by hand and eventually will do
ASP.Net controls (e.g. asp:Label) generate messy html ids (e.g. ct100_ct100_Yabba_Dabba_Doo_FinallyTheRealId). Yeah, they're ugly, but
In Clearcase I can generate a label for a given set of files and
I have a HQL query that can generate either an IList of results, or
Is there a tool that can generate sequence diagrams from running .NET code?
Is there an IDE out there that can generate XML from XSD? Not Oxygen
While for the most part you can generate the same MSIL, there are definitely
I'm working on a small app where I can generate a list of barcodes.
In F#, you can generate a set of numbers, just by saying [1..100]. I

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.