Published
Edited
Dec 14, 2019
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
html`<p id="demo"></p>`
Insert cell
html`<button onclick="document.getElementById('demo').innerHTML = Date()">The time is?</button>`
Insert cell
Insert cell
html`<button onclick="this.innerHTML = Date()">The time is?</button>`
Insert cell
html`<button onclick="this.innerHTML = Date(); this.innerHTML += 'date'">The time is?</button>`
Insert cell
Insert cell
html`<button onclick="displayDate()">The time is?</button>` // cell 1 (it won't work as it is not a global in the notebook)
Insert cell
html`<button onclick="${displayDate()}">The time is?</button>` // cell 2 (Mike is going to make this work soon)
Insert cell
demo1 = html`<p id="demo1"></p>` // with a name, this cell can be put forward
Insert cell
solution1 = Object.assign(html`<button>The time is?</button>`, {onclick: displayDate})
Insert cell
solution2 = {
const button = html`<button>The time is?</button>`;
button.addEventListener("click", displayDate);
return button;
}
Insert cell
solution3 = html`<button onclick=${displayDate}>The time is?</button>` // the new html make it work
Insert cell
function displayDate() {
return document.getElementById("demo1").innerHTML = new Date().toLocaleTimeString();
} // not working
Insert cell
Insert cell
viewof update = html`<button>Update the time`
Insert cell
{
update;
return new Date().toLocaleTimeString();
}
Insert cell
Insert cell
import {html, svg} from "@observablehq/htl"
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