Update a DOM element's field, attribute or CSS variable when source produces a value.
source
// Access via DOM query. Binds to 'textContent' by defaultbind(readableSource, `#someEl`);// Set innerHTML insteadbind(readableSource, someEl, { elField: `innerHTML` });// An attributebind(readableSource, someEl, { attribName: `width` });// A css variable ('--' optiona)bind(readableSource, someEl, { cssVariable: `hue` });// Pluck a particular field from source data.// Ie someEl.textContent = value.colourbind(readableSource, someEl, { sourceField: `colour` });// Transform value before setting it to fieldbind(readableSource, someEl, { field: `innerHTML`, transform: (v) => `Colour: ${v.colour}`}) Copy
// Access via DOM query. Binds to 'textContent' by defaultbind(readableSource, `#someEl`);// Set innerHTML insteadbind(readableSource, someEl, { elField: `innerHTML` });// An attributebind(readableSource, someEl, { attribName: `width` });// A css variable ('--' optiona)bind(readableSource, someEl, { cssVariable: `hue` });// Pluck a particular field from source data.// Ie someEl.textContent = value.colourbind(readableSource, someEl, { sourceField: `colour` });// Transform value before setting it to fieldbind(readableSource, someEl, { field: `innerHTML`, transform: (v) => `Colour: ${v.colour}`})
If source has an initial value, this is used when first bound.
Returns PipeDomBinding to control binding:
const bind = bind(source, `#someEl`);bind.remove(); // Unbindbind.remove(true); // Unbind and remove HTML element Copy
const bind = bind(source, `#someEl`);bind.remove(); // Unbindbind.remove(true); // Unbind and remove HTML element
If several fields need to be updated based on a new value, consider using bindUpdate instead.
Source of data
Element to update to, or query string such as '#someid'
Rest
Bindings
Update a DOM element's field, attribute or CSS variable when
source
produces a value.If
source
has an initial value, this is used when first bound.Returns PipeDomBinding to control binding:
If several fields need to be updated based on a new value, consider using bindUpdate instead.