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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:51:07+00:00 2026-06-12T22:51:07+00:00

Fiddle: http://jsfiddle.net/YbfZG/4/ For some reason the toggleDiv/removeDiv functions aren’t working (I haven’t used jsfiddle

  • 0

Fiddle: http://jsfiddle.net/YbfZG/4/ For some reason the toggleDiv/removeDiv functions aren’t working (I haven’t used jsfiddle much), but hopefully this will give you a better idea of what I’m trying to accomplish.

I’ve got a page where users can add items (divs) dynamically by making a selection from a dropdown. This is accomplished via .append(). They can also remove an item (.remove()) and potentially re-add it. Each div contains a hide/show area triggered by clicking on a link.

The first time a div is added to the page, the hide/show area works fine. If the same div is removed and then re-added, the hide/show no longer works. I believe this is because the div isn’t being completely removed from the DOM, so the hide/show function – which operates based on ids – can’t find the correct div to work on.

I’ve tried modifying my remove function to be $(this).empty().remove(); but that didn’t work. I also tried using detach as well, but there was no change in the functionality. I did some reading and I potentially need to be using .on(), but I’m not sure how to structure that.

ETA: Append & toggle code and changed div name to not be solely numeric (typo on my part).

  • 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-12T22:51:10+00:00Added an answer on June 12, 2026 at 10:51 pm

    It will be easier if you change your markup to:

    <div id="8" class="wrapper">
        <div>
        <a title="Remove" class="remove" href="#">Remove</a>
        </div>
    </div>
    

    (basically i added a “wrapper” class to the main div and a “remove” class to the remove link)

    So you’ll get rid of the onclick attribute and use a simple function instead:

    $('body').on('click','a.remove',function(){
        $(this).closest('div.wrapper').remove();
    });​
    

    Demo


    Given your full code, here’s how to make it work (demo) :

    $(function() {
    
        $('.elements').on('click', '.remove', function() {
            $(this).closest('div[id^=div]').remove();
        });
    
        $('.elements').on('click', '.open-close', function() {
            var hideShowN = $(this).closest('div[id^=div]').attr('id').replace(/\D/g,'');
            $('#hide_show_'+hideShowN).toggle();
        });
    
        $('.add').on('click', function() {
            $('.elements').append('<div id="div_8">Element<a class="open-close" href="#" title="Open/Close">Open/Close</a><div id="hide_show_8" style="display: none;">Stuff</div><a class="remove" href="#" title="Remove">Remove</a></div>');
        });
    
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Fiddle: http://jsfiddle.net/MhWm5/16/ I have some dynamically generated table rows/values with dynamic IDs <td class=control-group>
Concider the following fiddle: http://jsfiddle.net/dts2T/ This has been bugging me for quite some time
link to fiddle : http://jsfiddle.net/nEapJ/ (working) var items = [{ label : 'a', value
Here's me fiddle: http://jsfiddle.net/6yU6N/10/ I want to work some CSS magic on the table
Please see the fiddle ( http://jsfiddle.net/Jk6Bk/5/ ) I would like to add some spacing
See fiddle: http://jsfiddle.net/mrcarllister/Z2GjN/ Basically, I've got the click-drag-scroll working EXCEPT when you click and
Fiddle: http://jsfiddle.net/amitava82/dawkn/6/ The input elements will be generated dynamically based on json data received
I have following fiddle: http://jsfiddle.net/BFSH4/ As you see there are two issues: The h1
I have this fiddle: http://jsfiddle.net/yub2B/4/ HTML: <input type=text /> <input type=text /> <input type=text
In this fiddle http://jsfiddle.net/dAHqe/2/ I've created examples for the 2 main uses (that I've

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.