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%);
}