Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

Save Automatically?

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

              
                <!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="styles.css">
    </style>
</head>

<body>

    <button type="button" class="new-div">New Div</button>
    <main class="app">
        <!-- MOVEMENTS -->
        <div class="movements" id="init-div">
            <div class="movements__row" id="delete-row">
                <!--<div class="movements__date"></div>
                <div class="movements__value">Lorem ipsum dolor sit amet consectetur adipisicing elit. Cumque quibusdam
                    ipsa libero laudantium hic nihil consectetur eos optio reprehenderit ducimus, cupiditate eum tenetur
                    sunt iusto similique pariatur mollitia, distinctio necessitatibus! Lorem ipsum dolor sit amet
                    consectetur, adipisicing elit. Ullam voluptate expedita assumenda? Unde esse repellat vel saepe
                    fugit architecto pariatur inventore illum, ducimus ullam excepturi dolores, sed laboriosam, voluptas
                    modi.</div>-->
            </div>

            <script src="/script.js"></script>
</body>

</html>
              
            
!

CSS

              
                /*
 * Use this CSS to learn some intersting techniques,
 * in case you're wondering how I built the UI.
 * Have fun! 😁
 */

* {
    margin: 0;
    padding: 0;
    box-sizing: inherit;
}

html {
    font-size: 62.5%;
    box-sizing: border-box;
}

body {
    font-family: "Poppins", sans-serif;
    color: #444;
    background-color: #f3f3f3;
    height: 100vh;
    padding: 2rem;
}


/* MAIN */
.app {
    display: flex;
    position: relative;
    max-width: 100rem;
    margin: 4rem auto;
    gap: 2rem;
    /* NOTE This creates the fade in/out anumation */
    opacity: 100;
    transition: all 1s;
}

/* MOVEMENTS */


.movements {
    display: flex;
    flex-direction: column;
    background-color: #fff;
    border-radius: 1rem;
    border: 1px solid rgb(164, 164, 164);
    overflow: hidden;
}

.movements__row {
    padding: 2.25rem 4rem;
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
    border-bottom: 1px solid #eee;
}


#init-div {
    visibility: hidden;
}

.movements__date {
    display: flex;
    font-size: 1.1rem;
    text-transform: uppercase;
    font-weight: 500;
    color: #666;
}

.movements__value {
    font-size: 1.7rem;
    margin-left: auto;
}

.selected {
    color: red;
}
              
            
!

JS

              
                let divBtn = document.querySelector(".new-div")
let rowContainer = document.querySelector(".movements__row")
let mainContainer = document.querySelector("#init-div")
let time = new Date()
let year = time.getFullYear();
let day = time.getDate();
let date = time.getDay();
let currentDay = `${date}-${day}-${year}`;
let divNum = 0;
let thisOne;
let divArr = [];
let selectedDivs = [];
let dupeDivs;
let divObj = new Map;
let clickedItem;
let element;
let s = false;


divBtn.addEventListener('click', createDiv)


function createDiv() {
    divNum++;

    if (mainContainer.style.visibility = "hidden") {
        mainContainer.style.visibility = "visible"
    }

    html = `<div class="movements__row" class="alldivs" id="D${divNum}">
        <div class="movements__date">${currentDay}</div>
        <div class="movements__value">Lorem ipsum dolor sit amet consectetur adipisicing elit. Cumque quibusdam ipsa libero laudantium hic nihil consectetur eos optio reprehenderit ducimus, cupiditate eum tenetur sunt iusto similique pariatur mollitia, distinctio necessitatibus! Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ullam voluptate expedita assumenda? Unde esse repellat vel saepe fugit architecto pariatur inventore illum, ducimus ullam excepturi dolores, sed laboriosam, voluptas modi.</div></div>`;

    rowContainer.insertAdjacentHTML("beforebegin", html);

    //thisOne = document.querySelector(`[data-id="${divNum}"`)

    // divObj.set(`div${divNum}`, divNum)

    thisOne = document.getElementById(`${"D" + divNum}`)
    divArr.push(thisOne)
    //divArr.forEach((any, index, array) => {
    //   console.log(any.id)
    //  })

}

//Select Div
document.querySelector(".app").addEventListener("dblclick", function (e) {

    if (e.target !== e.currentTarget) {
        clickedItem = e.target.id
        selectedDivs.push(clickedItem);
        dupeDivs = [...new Set(selectedDivs)];
        selectedDivs = [...dupeDivs];
        element = document.getElementById(`${clickedItem}`);
        s = true;

    }

    if (element !== null && !element.classList.contains("selected")) {
        element.classList.add("selected");

    } else if (element !== null && s) {
        element.classList.remove("selected");
        s = false;
        selectedDivs.splice(e.target, 1);
        console.log("unselected", element);
        // console.log(element)
    }


    console.log(selectedDivs, divArr, s)

    let filtered = selectedDivs.filter((item, index) => selectedDivs.indexOf(item) !== index)


    //  if (selectedDivs.forEach((a, b, c) => {
    //      c.includes(a == e.target.id)
    //       console.log("yes")
    //   }))

    // if (!element.classList.contains("selected")) {
    //     element.classList.add("selected")
    //     s = true

    // }
    // else {
    //     element.classList.contains("selected")
    //     element.classList.remove("selected")
    //     s = false
    // }


})


document.addEventListener("keydown", (event) => {

    selectedDivs.forEach((div, index, ray) => {

        if (event.key === 'd' && s && element !== null) {
            console.log('deleted')
            divArr.splice(event.target, div);
            ray.splice(event.target, div);
            element = document.getElementById(`${div}`)
            element.remove()
            element.classList.remove("selected");
            s = false;
            console.log(selectedDivs, divArr, s)
        }
    })

})



              
            
!
999px

Console