Completely destroy block from function (ephemeral block)

How can I destroy a block in a function? I know I can set the innerHTML but that leaves some residue and whitespace. I’m looking to create a sort of “ephemeral block” that disappears when you push a button

Simply call element.remove() to detach an element from the DOM.

You may want to have a look at the MDN documentation to discover more methods that you’ll find essential.

It doesn’t work on input fields that were created using the snippet

What snippet? You haven’t shared any code.

The snippet built in to observable.

viewof text = Inputs.text({label: "Name"})

If you want to toggle the visibility of an input in another cell, you can reference it via its viewof prefix:

htl.html`<button onclick=${() => {viewof text.style.display = 'none'}}>Hide text`

However you cannot completely collapse the empty space, as cells have a minimum height.


Please also note that you’ll receive better answers if you put more care into your questions and add all details upfront, ideally with a link to a notebook that demonstrates the problem.