This is how I make copy buttons to grab the text of elements with bitty
Output
Text to copy
HTML
<bitty-4-0data-connect="TextCopierExample"><divdata-receive="copyElementText">Text to copy</div><buttondata-send="copyElementText">Copy Text</button></bitty-4-0>
JavaScript
window.TextCopierExample=class{
#copyTimeout = null;
asynccopyElementText(event,el){try{awaitnavigator.clipboard.writeText(el.innerText);event.target.innerHTML="Copied";if(this.#copyTimeout!==null){clearTimeout(this.#copyTimeout);}this.#copyTimeout=setTimeout(()=>{event.target.innerHTML="Copy";},1500);}catch(error){event.target.innerHTML="Could not copy";console.error(`Could not copy selection to clipboard: ${error}`)}}}