On Monday, August 7, 2023 at 11:17:58 AM UTC-5, luserdroog wrote:
> Is there a simpler gymnastics to set the id on an element
> in a document fragment, just before you append it into the
> DOM? I got this working but it feels heavy handed. Would some
> wild object decomposition/comprehension let me set the inner
> id and return the outer fragment in a one-liner?
>
Oops. Sorry for the fuss. That's what a function is for. duh.
<html>
<body>
<template id="clickbox">
<click-box cycle
states="empty checkmark xmark questionmark"
empty=""
checkmark="✓"
xmark="✖"
questionmark="?"></click-box>
</template>
</body>
<script src="click.js"></script>
<script>
function newbox( id ){
let box = clickbox.content.cloneNode( true );
box.querySelector("click-box").id = id;
return box;
}
var clickbox = document.querySelector("#clickbox");
var box1 = newbox( "box1" );
var box2 = newbox( "box2" );
var box3 = newbox( "box3" );