Tips for relocating a div panel below all other div panels when a button is clicked with JQuery and CSS

There are several panels stacked below each other.

Each panel has a button that, when clicked by the user, should move the panel to the bottom of the stack.

For example: If there are 10 panels aligned sequentially and the user wants to remove Panel 2 by clicking the button, it should move below all other panels and become the 10th Panel. (No need to change IDs or values, just a simple movement without animation)

Any suggestions on how to achieve this using CSS or JQuery?

Here is a scenario for reference:

Fiddle: https://jsfiddle.net/k5491Lg3/

<div id="accountInfo" class="accountInfo">
    <div id="accountTrue">
        <div class="accout newAccountPanel wrapper">
                <h3 class="boldText">
                    Play with Person 1
                </h3>
                <div class="fieldset OneAccordion person">
                        I AM SWEET PANEL 1
                    <!-- End panel -->
                    <input type="button" id="toBeRemoved1" value="Remove it Later" />
                </div>
                <!-- End fieldset -->
        </div>

        <div class="accout newAccountPanel wrapper">
                <h3 class="boldText">
                    Play with Person 2
                </h3>
                <div class="fieldset OneAccordion person">
                        I AM SWEET PANEL 2
                    <!-- End panel -->
                    <input type="button" id="toBeRemoved2"  value="Remove it Later"  />
                </div>
                <!-- End fieldset -->
        </div>

        <div class="accout newAccountPanel wrapper">
                    <h3 class="boldText">
                        Play with Person 3
                    </h3>
            <div class="fieldset OneAccordion person">
                    I AM SWEET PANEL 3
                <!-- End panel -->
                <input type="button" id="toBeRemoved3"  value="Remove it Later"  />
            </div>
            <!-- End fieldset -->
        </div>
    </div>
</div>

Answer №1

Give this a shot,

HTML,

<div id="accountInfo" class="accountInfo">
    <div id="accountTrue">
        <div class="accout newAccountPanel wrapper">
                <h3 class="boldText">
                    Play with Person 1
                </h3>
                <div class="fieldset OneAccordion person">
                        I AM SWEET PANEL 1
                    <!-- End panel -->
                    <input type="button" value="Remove it Later" class="btn-remove" />
                </div>
                <!-- End fieldset -->
        </div>

        <div class="accout newAccountPanel wrapper">
                <h3 class="boldText">
                    Play with Person 2
                </h3>
                <div class="fieldset OneAccordion person">
                        I AM SWEET PANEL 2
                    <!-- End panel -->
                    <input type="button" value="Remove it Later" class="btn-remove"  />
                </div>
                <!-- End fieldset -->
        </div>

        <div class="accout newAccountPanel wrapper">
                    <h3 class="boldText">
                        Play with Person 3
                    </h3>
            <div class="fieldset OneAccordion person">
                    I AM SWEET PANEL 3
                <!-- End panel -->
                <input type="button" value="Remove it Later" class="btn-remove"  />
            </div>
            <!-- End fieldset -->
        </div>
    </div>
</div>

JS,

$("#accountTrue").on("click", ".btn-remove", function(){
    var thisElement = $(this).closest('.accout');
    $(thisElement).appendTo("#accountTrue");
});

Check out the demo: https://jsfiddle.net/k5491Lg3/3/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The $_POST variable is not filled with the information displayed in the payload

When submitting a form with AJAX, I am able to view the payload data using the developer tools in Chrome: ------WebKitFormBoundaryiwCAdpY9aJH3D9h9 Content-Disposition: form-data; name="datafixId" 666 ------WebKitFormBoundaryiwCAdpY9aJH3D9h9 Content-Dispo ...

Setting up the Laravel backend to work with the server side of Backbone's urlRoot

As I delve into learning backbone.js, I find myself struggling with the server-side aspect of things. I've come across documentation suggesting to set the urlRoot as 'user/', which indicates a RESTful API. However, adapting this structure w ...

use angularjs directive to position a div absolutely aligned with the right edge of another div

I am attempting to use an angularjs directive to align the right side of an absolute div with another div. The code is working, but I am encountering an issue where the children divs are slightly wider than their parent, causing the offsetWidth value to be ...

Employ a pivot table to visually display an array of object data

I am attempting to utilize a pivot table to organize the data provided below: $.pivotUtilities.tipsData=[ {status:"open",year:2014,value:100.00}, {status:"open",year:2015,value:200.00}, {status:"open",year:2016,va ...

How can we prevent an unstyled list from causing text to drop to the next row?

As I am not an expert developer, I am in the process of creating a basic menu card using bootstrap. To keep it simple, I decided to use an unstyled list and added a span with float: right to ensure that the price is always aligned to the right. However, I ...

Using mongoose to differentiate whether an update-upsert operation is performing an insert or an update

Is the "upsert" option for updating working correctly? I attempted to upsert an object into mongodb twice with the same key, but did not receive an inserted message. Am I overlooking something? (mongodb : v2.6.3; mongoose : 3.8.15) Member.findOneAndRemov ...

What is the process for transferring input field values to PHP?

I am working on setting up a database and login form, and I need to create a PHP script to validate the login credentials. What are the different types of data access and how can they be utilized? Specifically, how do I retrieve user input from elements ...

What is the best way to locate and extract the content of an HTML element using XPath in Selenium with VBA?

I am currently seeking a solution to extract the content of an element with the name "data-testid" from a website. This specific element appears approximately 35 times within various contexts in the HTML code. The particular element I am interested in look ...

Using HTML5 Canvas with Firefox 4: How to Retrieve Click Coordinates

Lately, I've been diving into creating HTML5 Video and Canvas demos. Initially, my focus was on optimizing them for Chrome, but now I'm shifting my attention to Firefox and Safari as well. One particular demo I'm currently working on involv ...

Use PHP code to echo a clear division after every third result in MySQL

I am currently displaying results in descending order from a MySQL table using a while loop. I have already set up a pagination system that displays 9 records per page. However, I am facing an issue when trying to implement a CSS break every 3 records in ...

Clicking our way back through the loop

Looking to display a name when each item is clicked. I've assigned an ID to each element, but it seems like I'm overlooking something. In the current code, I'm thinking there should be a variable involved, but I'm uncertain: $(document ...

Tips for adding a Search Bar to the header in a React Native application

I've been working on creating a header for my app in React Native that includes the screen title, a back button, and a search bar spanning the width of the screen. However, I've encountered some challenges along the way. Initially, I began with ...

Error: Module not found - Imported Node Module

I have been struggling to make modifications to an npm package with little success. I have spent hours troubleshooting and would greatly appreciate some guidance. https://www.npmjs.com/package/dxf After forking the package into my Github account, I proce ...

JS How can I generate individual buttons in a loop that trigger separate actions?

Currently, I am working with loops in jQuery to create a series of boxes that contain specific values. The problem arises when I try to assign actions to each box based on the values from an array. For example, I want each box to trigger a different alert ...

What is the best way to conduct a Javascript test using Jasmine?

I'm encountering an issue with testing this JavaScript code: $("#ShootBtn").on('click', () => foo.testFunc()); var foo = { testFunc: function() { hub.server.shoot(true, username, gameCode); } } For my testing framework, ...

Using React and Ant Design: Sharing state between multiple <Select> components within a <Form> element

Just getting started with ReactJS and AntDesign. Currently, I am working on connecting a series of <Select> components to share state. The goal is for the selection made in the first dropdown to dynamically update the options available in the follow ...

Looking to display a page header alongside an image on the same page

I'm currently learning React.js and working on my very first app. As someone new to frontend development, I am aiming to have a header design similar to that of popular websites like StackOverflow or YouTube, where an image or icon is positioned just ...

What is the best way to eliminate excess spacing between HTML td and table elements in Outlook?

Here's the HTML email code snippet. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Co ...

The default value is not displayed in the Angular dropdown menu

When using regular html select menus, if you create an option element with selected and disabled attributes and provide text for that option, the text will be displayed by default in the select menu. Below is a basic example of HTML code: <select name= ...

Is there a way to restrict the number of times I can utilize slideToggle function?

When I continuously click on a div element in an HTML website that triggers the .slideToggle() method, it will keep opening and closing for as many times as I click. The problem arises when I stop clicking, as the <div> continues to toggle open and c ...