โœจclosing button [x]

browser โŸฉ event โŸฉ type โŸฉ mouse โŸฉ click โŸฉ example โŸฉ closing button

add a closing button [x] for every <div class="pane">.

const { log } = console

// โญ๏ธ import
import { $, $all } from './js/ext/Node_ext.js';        // ๐Ÿ‘” Node + ext
// ---------------------------------------------------------------

// elements
const panes = $all('.pane');                // <div class="pane">

panes.forEach(pane => {
    
    // โญ๏ธ create "[x] buttons"
    pane.insertAdjacentHTML(
        "afterbegin", 
        '<div class="x-button">[x]</div>'
    );
    
    // โญ๏ธ <div class="x-button"> becomes `pane.firstChild`
    pane.firstChild.onclick = () => {
        pane.hidden = true;
    };
    
});

// show all panes again
$('#showAll').onclick = () => {
    panes.forEach(pane => pane.hidden = false);
};

๐Ÿ“ CSS

.pane {
    position: relative;    /* โญ๏ธ new coord system */
}

.pane .x-button {
    position: absolute;    /* โญ๏ธ relative to .pane */
    top: 4px;
    right: 4px;
    color: orange;
    cursor: pointer;
    font-family: monospace;
}

.pane h3 {
    color: hsl(225 80% 80%);
}

Last updated