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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:47:45+00:00 2026-06-03T23:47:45+00:00

I am working on a system that allows the user to generate objects from

  • 0

I am working on a system that allows the user to generate objects from objects. It is similar to the Win7 sticky note system; a sticky note can make a new sticky note, and delete itself. I am trying to implement this with jquery, yet there is a duplication issue when i try to add new objects.

In jquery i tell the code to make a second “object” which is a variable that holds the html for an object that contains an add and delete button in it. If you view the html page, it makes more sense. When I tell jquery to make the object, it does perfectly. Except that the object that it made does not make more objects! jquery for some reason does not recognize the presence of the new object that it just created. And as a solution i tried restating the .click() functions that listen for the user to click on the add or delete buttons. That only made it multiply the amount whenever i added a new object, and this whole time the delete button has not been functioning properly.

Can someone please fix my code?

<html>
    <head>
        <style type="text/css">
            .environment {height:500px; width:500px; border:1px solid black;background:lightyellow;text-align:center;overflow:auto;}
            .object {height:50px; width:40%;border:1px solid black;background:#F0F0F0;padding:5px;margin:5px;float:left;}
            .delObject {float:right;}
        </style>
        <script type="text/javascript" src="jquery-1.7.2.js"></script>
        <script type="text/javascript">
            var object = "<div class='object'>object<br /><button class='addObject'>addObject()</button><button class='delObject'>delObject()</button></div>";
            $(function() {
                $(".addObject").click(function(){addObject()});
            });
            $(function() {
                $(".delObject").click(function(){
                    $(this).parent().remove();
                });
            });
            function addObject() {
                $(object).appendTo(".environment");
                $(function() {
                    $(".addObject").click(function(){addObject()});
                });
                $(function() {
                    $(".delObject").click(function(){
                        $(this).parent().remove();
                    });
                });
            }
        </script>
    </head>
    <body>
        <div class="environment">environment<br />
            <div class="object">object<br />
            <button class="addObject">addObject()</button>
            <button class="delObject">delObject()</button>
        </div>
        </div>
    </body>
</html>

If this all seems too complicated, can someone please tell me of a way in which i can make html objects in jquery, which are capable of making and deleting more of themselves without using the .clone() function.

  • 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-03T23:47:47+00:00Added an answer on June 3, 2026 at 11:47 pm

    Event delegation.

    $(function(){
        var object = "<div class='object'>object<br /><button class='addObject'>addObject()</button><button class='delObject'>delObject()</button></div>";
        $( ".environment" )
            .on( "click", ".addObject", function () {
                $( object ).appendTo( ".environment" );
            })
            .on( "click", ".delObject", function () {
                $( this ).parent().remove();
            });        
    });
    

    The reason your code multiplies on each click is you are adding an additional click event to all existing elements with said class every time you add a new one. With event delegation, you no longer need to bind an event to each element, instead, the ancestor element (.environment) handles the events.

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

Sidebar

Related Questions

I'm working on a system that relies in $_SERVER['REMOTE_ADDR'] to get the user address
I am working on a system that has been hashing user passwords with MD5
I'm working on a legacy system that has uses stored procs, business objects and
I am working on a project at the moment, that allows the user to
I'm working on an online system that allows users to interact socially and of
I am working on an ActiveX tool that allows users to copy data from
I'm working on a jsp page that the user can browse through collection of
I'm working with a system that consists of several applications and services, almost all
I am working on a system that performs continuous integration and I am looking
I am working on a legacy system that generates confirmation numbers based on the

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.