D3 and Custom Data Attributes
✓ Published0🌍 Public
Mmbostock
Last edited Feb 9, 2016
Created on Oct 28, 2011
This example shows how D3’s `datum` operator can read HTML5 custom data attributes from DOM elements and use that data for sorting. The code selects all list items, binds each element’s `dataset` object—containing the `username` attribute—via `.datum()`, then reorders the list with `.sort()` based on `d3.ascending` on the username values. It uses D3 v3 directly on a static, two-item unordered list, making no external data requests or canvas rendering.
AI-generated descriptiongpl-3.0 Licensed