Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                 <div class="container py-5">
        <h2 class="my-3">Drag and drop between lists</h2>

        <div class="row">
            <div class="col-6">
                <div id="firstList" class="parent">
                    <div class="card shadow-sm rounded my-1 draggable border-0" draggable="true" id="tomato">
                        <div class="card-body d-flex justify-content-between">    
                            <span>
                                tomato
                            </span>
                            <button type="button" class="btn btn-sm btn-outline-danger rounded-circle remove-btn">
                                <i class="bi bi-x"></i>
                            </button>
                        </div>
                    </div>
                    <div class="card shadow-sm rounded my-1 draggable border-0" draggable="true" id="potato">
                        <div class="card-body d-flex justify-content-between">    
                            <span>
                                potato
                            </span>
                            <button type="button" class="btn btn-sm btn-outline-danger rounded-circle remove-btn">
                                <i class="bi bi-x"></i>
                            </button>
                        </div>
                    </div>
                    <div class="card shadow-sm rounded my-1 draggable border-0" draggable="true" id="cucumber">
                        <div class="card-body d-flex justify-content-between">    
                            <span>
                                cucumber
                            </span>
                            <button type="button" class="btn btn-sm btn-outline-danger rounded-circle remove-btn">
                                <i class="bi bi-x"></i>
                            </button>
                        </div>
                    </div>
                    <div class="card shadow-sm rounded my-1 draggable border-0" draggable="true" id="carrot">
                        <div class="card-body d-flex justify-content-between">    
                            <span>
                                carrot
                            </span>
                            <button type="button" class="btn btn-sm btn-outline-danger rounded-circle remove-btn">
                                <i class="bi bi-x"></i>
                            </button>
                        </div>
                    </div>
                    <div class="card shadow-sm rounded my-1 draggable border-0" draggable="true" id="onion">
                        <div class="card-body d-flex justify-content-between">    
                            <span>
                                onion
                            </span>
                            <button type="button" class="btn btn-sm btn-outline-danger rounded-circle remove-btn">
                                <i class="bi bi-x"></i>
                            </button>
                        </div>
                    </div>
                    <div class="card shadow-sm rounded my-1 draggable border-0" draggable="true" id="lettuce">
                        <div class="card-body d-flex justify-content-between">    
                            <span>
                                lettuce
                            </span>
                            <button type="button" class="btn btn-sm btn-outline-danger rounded-circle remove-btn">
                                <i class="bi bi-x"></i>
                            </button>
                        </div>
                    </div>
                    <div class="card shadow-sm rounded my-1 draggable border-0" draggable="true" id="corn">
                        <div class="card-body d-flex justify-content-between">    
                            <span>
                                corn
                            </span>
                            <button type="button" class="btn btn-sm btn-outline-danger rounded-circle remove-btn">
                                <i class="bi bi-x"></i>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-6">
            <div id="secondList" class="parent">
                    <div class="card shadow-sm rounded my-1 draggable border-0" draggable="true" id="apple">
                        <div class="card-body d-flex justify-content-between">    
                            <span>
                                apple
                            </span>
                            <button type="button" class="btn btn-sm btn-outline-danger rounded-circle remove-btn">
                                <i class="bi bi-x"></i>
                            </button>
                        </div>
                    </div>
                    <div class="card shadow-sm rounded my-1 draggable border-0" draggable="true" id="peach">
                        <div class="card-body d-flex justify-content-between">    
                            <span>
                                peach
                            </span>
                            <button type="button" class="btn btn-sm btn-outline-danger rounded-circle remove-btn">
                                <i class="bi bi-x"></i>
                            </button>
                        </div>
                    </div>
                    <div class="card shadow-sm rounded my-1 draggable border-0" draggable="true" id="banana">
                        <div class="card-body d-flex justify-content-between">    
                            <span>
                                banana
                            </span>
                            <button type="button" class="btn btn-sm btn-outline-danger rounded-circle remove-btn">
                                <i class="bi bi-x"></i>
                            </button>
                        </div>
                    </div>
                    <div class="card shadow-sm rounded my-1 draggable border-0" draggable="true" id="fig">
                        <div class="card-body d-flex justify-content-between">    
                            <span>
                                fig
                            </span>
                            <button type="button" class="btn btn-sm btn-outline-danger rounded-circle remove-btn">
                                <i class="bi bi-x"></i>
                            </button>
                        </div>
                    </div>
                    <div class="card shadow-sm rounded my-1 draggable border-0" draggable="true" id="raspberry">
                        <div class="card-body d-flex justify-content-between">    
                            <span>
                                raspberry
                            </span>
                            <button type="button" class="btn btn-sm btn-outline-danger rounded-circle remove-btn">
                                <i class="bi bi-x"></i>
                            </button>
                        </div>
                    </div>
                    <div class="card shadow-sm rounded my-1 draggable border-0" draggable="true" id="lemon">
                        <div class="card-body d-flex justify-content-between">    
                            <span>
                                lemon
                            </span>
                            <button type="button" class="btn btn-sm btn-outline-danger rounded-circle remove-btn">
                                <i class="bi bi-x"></i>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <hr>

        <div id="unassignedItemsElement" class="my-2 parent">
        </div>

        <form id="form" class="row g-3">
            <div class="col-auto">
                <label for="addNewItem" class="visually-hidden">Add new item</label>
                <input type="text" class="form-control" id="addNewItem" placeholder="Add new item...">
            </div>
            <div class="col-auto">
                <button type="submit" class="btn btn-primary shadow">Add</button>
              </div>
        </form>
    </div>
              
            
!

CSS

              
                .draggable {
  cursor: move;
  user-select: none;
}
              
            
!

JS

              
                document.addEventListener("DOMContentLoaded", (ev) => {
  const unassignedItemsElement = document.querySelector("#unassignedItemsElement");
  const addNewItem = document.querySelector("#addNewItem");
  const form = document.querySelector("#form");
  const lists = document.querySelectorAll(".parent");

  let dragEl = null;

  form.addEventListener("submit", (e) => {
    e.preventDefault();
    addUnassignedElement(addNewItem.value);
    addNewItem.value = "";
  });

  function addUnassignedElement(element) {
    const id = `${element}-${Math.floor(Math.random() * 100) + 1}`;
    unassignedItemsElement.innerHTML += `
      <div class="card shadow-sm rounded my-1 draggable border-0" draggable="true" id="${id}">
          <div class="card-body d-flex justify-content-between">
            <span>
                ${element}
            </span>
            <button type="button" class="btn btn-sm btn-outline-danger rounded-circle remove-btn">
                <i class="bi bi-x"></i>
            </button>
          </div>
      </div>`;
    loopListItems();
  }

  function onDragStart(event) {
    dragEl = this;
    event.dataTransfer.effectAllowed = "move";
    event.dataTransfer.setData("node", this.id);
    return false;
  }

  function onDragOver(event) {
    if (event.preventDefault()) {
      event.preventDefault();
    }

    event.dataTransfer.dropEffect = "move";
    return false;
  }

  function onDrop(event) {
    if (event.stopPropagation()) {
      event.stopPropagation();
    }

    if (dragEl !== this) {
      dragEl = this;
      if (this.parentNode !== unassignedItemsElement) {
        this.parentNode.insertBefore(document.getElementById(event.dataTransfer.getData("node")), this.nextSibling);
      }
    }

    dragEl = null;
    return false;
  }

  function removeItem(event) {
    this.parentNode.parentNode.remove()
  }

  function loopListItems() {
    lists.forEach((list) => {
      const listItems = list.querySelectorAll(".draggable");
      listItems.forEach((item) => {
        item.addEventListener("dragstart", onDragStart, false);
        item.addEventListener("dragover", onDragOver, false);
        item.addEventListener("drop", onDrop, false);
        item.querySelector(".remove-btn").addEventListener("click", removeItem);
      });
    });
  }

  loopListItems();
});

              
            
!
999px

Console