Hi there!
Can someone please tell me how can I implement viewof operator in normal js.
I can’t use observable everywhere on a website so please help me.
Thanks.
A cell declaration like viewof n = …
creates two variables: viewof n
, which is just a regular DOM element (and is the thing you see in the cell), and n
, which refers to the value
property of the DOM element and is updated when the DOM element fires an input
event.
// the DOM element
const n = document.querySelector("input")
// listening for and logging new values
n.addEventListener("input", e => console.log(e.currentTarget.value));
2 Likes