bitty installation snippets examples documentation q&a

snippets

use innerHTML as a number

  • bitty adds convenience methods to elements including el.innerHTMLAsInt() and el.innerHTMLAsFloat() which provide access to the innerHTML of an element as a number.
  • See the element methods section of the documentation for more.

html

<button data-s="doubleInt" data-r="doubleInt">1</button>
<button data-s="doubleFloat" data-r="doubleFloat">1.1</button>

javascript

export const b = {};

export function doubleInt(_, __, el) {
  el.innerHTML = el.innerHTMLAsInt() * 2;
}

export function doubleFloat(_, __, el) {
  el.innerHTML = el.innerHTMLAsFloat() * 2;
}