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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:35:43+00:00 2026-06-13T07:35:43+00:00

I have two areas, one area is for enabled items, the other is for

  • 0

I have two areas, one area is for enabled items, the other is for disabled items. The user can click on Add to send the content to the enabled area.

The problem is, when I change the class of the form to make it delete instead of add, nothing happens.

I’ve made a jsfiddle of the issue. You’re suppose to be able to switch back and forth how many times you wish, not just once.

You can see in the source that the class names are actually changing but it seems that my jQuery function doesn’t recognize the change.

Please see the jsfiddle-example below:

http://jsfiddle.net/crW9m/7/

Here’s my HTML markup:

<div class="added">
<form class="add">
<h3>One item </h3>
 <input type="submit" value="Add" />
</form>
    </div>


 <div class="deleted">
    <form class="delete">
        <h3>Second item </h3>    
         <input type="submit" value="Delete" />
    </form>
    </div>

    <div id="destination">
        <p>Destination for added items</p>
    </div>
    <div id="destination2">
        <p>Destination for deleted items</p>
    </div>

and here’s the jQuery code that goes with it:

    $(document).ready(function() {
    $(".add").click(function(event){

    var $form = $(this),           
        $inputs = $form.find("input, select, button, textarea"),            
        serializedData = $form.serialize();


            $form.removeClass("add").addClass("delete");
        $inputs.val('Delete');
            $form.appendTo("#destination");


    // prevent default posting of form
    event.preventDefault();
    });

       $(".delete").click(function(event){        
        var $form = $(this),        
        $inputs = $form.find("input, select, button, textarea"),

        serializedData = $form.serialize();


            //var submit = $form.find(":submit").hide();
            $form.removeClass("delete").addClass("add");
            $inputs.val('Add');
            $form.appendTo("#destination2");


    // prevent default posting of form
    event.preventDefault();
    });     


  });
​
  • 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-13T07:35:45+00:00Added an answer on June 13, 2026 at 7:35 am

    I’ve created an updated version of your script.

    http://jsfiddle.net/crW9m/9/

    My only change was to use delegate (jQuery function on) instead of your click event. The click event is added to the actual elements matching the selector when the script is run (on page load usually). If other elements are added later they will not be affected by the event since the event was added to specific elements and not to the general selector. A delegate solves this by checking for matching elements on the actual event.

    // $(".delete").click(function(event){ /*...*/ }); // Replace this with:
    $(document).on('click', '.delete', function(event){ /*...*/ });
    
    // $(".add").click(function(event){ /*...*/ }); // And replace this with:
    $(document).on('click', '.add', function(event){ /*...*/ });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one area of space and two body's of text to show. I
I have two types User and Area . public class User : IEntity {
I have two NSViews on top of each other. One NSView presents a table
I have two div elements on a page. How can I make one div
I have two classes, one Circle() and the other GeometricObject(). I have to extend
i have two domains setup one called fastcms.com and the other is called fastautos.com
I have two geo-spatial simple convex polygon areas, in latitudes and longitudes (decimal degrees)
I am continuing to enslave the MVC 2 thing: Areas... Now I have two
I have two classes; Area and LanguageArea . I use LanguageArea to handle translated
I have an image map with two different area shape attributes. I want to

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.