How to attach a plot to a DOM element | Fil | Observable
ojs
ojs
Author
Fil
@fil
Vocateur.
Comments (2)
Murat Anlı
Mar 21, 2023
It looks like each time the plot is redrawn a new plot object is appended to the <div> element. Is there a way to fix that behavior where the newly generated plot object replaces the already existing one?
Fil
Mar 21, 2023
Sure! What Plot returns is a "standard" DOM node. It's possible to empty the #container before appending it, or select the previous node and use
https://developer.mozilla.org/en-US/docs/Web/API/Element/replaceWith
.
Reply
Add comment
Subscribe to notifications
© 2026 Observable, Inc.
Terms of service
Privacy policy
Product
About
Pricing
Documentation
Release notes
Contact us
Open source
Notebook Kit
Plot
D3
Community
Public
Forum
Bluesky
YouTube
X
Observable
Sign up
Fil
2
Reply
Add comment
Subscribe to notifications
1
How to attach a plot to a DOM element | Fil | Observable