bitty installation snippets examples documentation q&a

snippets

copy text with selector

This is the target text to copy
  • The b.copy(selector) method copies text from the element with the given selector.
  • The .value is copied if it exists. Otherwise, the .innerHTML is copied.
  • If you want feedback (e.g. changing "Copy Text" to "Copied" for a short interval), you can roll your own or use the b.quickCopy method.

html

<div id="targetDiv">This is the target text to copy</div>
<button data-s="copier">Copy Text</button>

javascript

export const b = {};

export async function copier(_, __, ___) {
  await b.copy("#targetDiv");
}