D3.js selection.exit() Function
✓ Published0🌍 Public
This example demonstrates how D3.js’s `selection.exit()` function removes DOM elements that no longer have corresponding data after a data update. The code initially creates green `<div>` elements for three data items (“geeks”, “for”, “geeks”) using `d3.selectAll("div").data(...).enter().append()`. It then binds a new four-item dataset (`"DIVS UPDATED"`, `"GEEKS"`, `"FOR"`, `"GEEKS"`) with a key function, appends new divs for entering data, and calls `div.exit().remove()` to delete the old divs whose keys are missing from the updated dataset. The page uses D3 v4 from the official CDN, with styling defined in a `<style>` block.
AI-generated descriptionMIT Licensed