Published
Edited
Mar 1, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof buttonWithValue = Button("Text on Button", {
label: "Click me:",
reduce: functionRunOnClick
})
Insert cell
functionRunOnClick = function() {
textChangedByButton.innerHTML = `<hr><h3><i>The Window of Change</i></h3>
Text <i>after</i> clicking button.<hr>`;
return "value of buttonsValue";
}
Insert cell
buttonWithValue
Insert cell
Insert cell
Insert cell
Insert cell
viewof selection = Select(["Nothing"].concat(["This", "That", "The Other"]), {
label: "Choose:"
})
Insert cell
{
let text = ``;
if (selection == "Nothing")
text = `<hr><h3><i>The Window of Change</i></h3>
Text <i>before</i>.<hr>`;
else
text = `<hr><h3><i>The Window of Change</i></h3>
Text <i>after</i> selecting ${selection}.<hr>`;
textChangedBySelect.innerHTML = text;
}
Insert cell
selection
Insert cell
Insert cell
Insert cell
textChangedByText = html`<hr><h3><i>The Window of Change</i></h3>
Text <i>before</i>.<hr>`
Insert cell
viewof textInput = Text({
label: "Type something:",
placeholder: "Yes, type over me ..."
})
Insert cell
Insert cell
{
let text = ``;
if (textInput == "")
text = `<hr><h3><i>The Window of Change</i></h3>
Text <i>before</i>.<hr>`;
else
text = `<hr><h3><i>The Window of Change</i></h3>
Text <i>after</i>: ${textInput}.<hr>`;
textChangedByText.innerHTML = text;
}
Insert cell
textInput
Insert cell
Insert cell
whichKey = document.addEventListener('keypress', e => {
return e.key;
if (e.key == "Enter") return "Enter pressed";
})
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more