Published
Edited
May 25, 2020
Insert cell
Insert cell
Insert cell
{
const stuff = html`<h2>Hello</h2><script type="module">console.log('asdf');</script>`;
runScript(html`<script>
console.log("Script is running now.");
document.getElementsByTagName('h2')[0].style.color = 'green';
</script>`);
return stuff;
}
Insert cell
function runScript(script) {
// setTimeout so that DOM you wanted to manipulate is probably mounted
setTimeout(() => {
var newScript = document.createElement("script");

newScript.text = script.text;
newScript.type = script.type;
document.head.appendChild(newScript); //.parentNode.removeChild(script);
});
}
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