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

  • Home
  • SEARCH
  • 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 7839025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:17:43+00:00 2026-06-02T15:17:43+00:00

I have a button that creates paragraphs dynamically in a div along with an

  • 0

I have a button that creates paragraphs dynamically in a div along with an ID.
When you create a paragraph you can also select that paragraph (“background color changes”) by clicking it, along with that (“When you click on paragraph”) a div is created with a link inside of it.
Tried to remove individually but it would remove all the paragraphs at once

How can I remove a paragraph that is being selected(“I mean individually”)?

Here is link and what I have so far:

http://jsfiddle.net/RzvV5/88/

Javascript/jQuery Code:

$(document).ready(function(){
    var id = 1;
    $("#push").on({
        click: function(){
            var pr = $('<p class="test">This is text ' + id + '</p>');
            var d = $("#Test");
            var pclone = $(pr).clone();
            pclone.on({
                mouseenter: function(){    
                    $(this).addClass("inside");
                },
                mouseleave: function(){                             
                    $(this).removeClass("inside"); 
                },
            });
            pclone.appendTo(d);
            id++;
        }
    });

    var div =  $('<div class="customD" id="d"></div>');
    var del = $('<a href="#" class="delete" id="erase">Delete</a>');
    var pcust = $(div).clone();
    var pdel = $(del).clone();

    $("#Test").on("click", "p", function(){ 
        var cur = $(this).css("background-color");

        if(cur=="rgb(255, 255, 255)") {  
            $(this).css("background-color","red").addClass("help insider");
            $(this).after(pcust);
        } 
        else { 
            $(this).css("background-color","white").removeClass('help insider');
            $(pcust).remove();
        }    

        $(pcust).append(pdel);

    }); 
});

HTML Code:

<html>
<body>
    <a href="#" id="push">Push</a>
    <div id="Test"></div>
</body>
</html>

CSS Code:

.test { color: #000; padding: .5em; margin: 0px; border: 2px solid white; background: white;} 

.help { border: 2px dashed #FDD }

.inside { border: 2px solid red    }

.insider { border: 2px solid #FDD; }

.delete {  font-size: 12px; }
.customD { background: yellow}
  • 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-02T15:17:45+00:00Added an answer on June 2, 2026 at 3:17 pm

    You can add click event handler to delete link

     $(".delete").live("click",function(){
            $(this).parent().prev().remove();
            $(this).remove();
        });
    

    BTW. You don’t have to clone each time link and its parent div, you can build up that part of dome and hold same reference, if you reuse it with

    var div =  $('<div class="customD" id="d"></div>');
    var del = $('<a href="#" class="delete" id="erase">Delete</a>');
    div.append(del);
    
        $("#Test").on("click", "p", function(){ 
    
           ....
           $(pcust).append(del); //this will not clone delete div, it will actually replace its position it dome structure and move it from one paragraph to "pcust". This will save memory!!!
    
            ....
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that dynamically creates a new button through JavaScript that when
I have a Delphi program that creates HTML files. Later when a button is
I have created a button CSS class that uses background images with different positions
In Java, I have an object that creates a button. Inside that button's onclicklistener
I have a SWING UI that contains a button that creates a new SwingWorker
I have a button on a website that creates a directory and copys a
I have an iPad project I'm working on that dynamically creates a number of
I have some code below that creates a RelativeLayout and adds a button to
I'm using Ruby/Rails to dynamically create a div and button through a loop, and
I have a button that creates a new drop pin. That pin is in

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.