Skip to content

Instantly share code, notes, and snippets.

@mbostock
Last active February 9, 2016 00:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mbostock/1323729 to your computer and use it in GitHub Desktop.
Save mbostock/1323729 to your computer and use it in GitHub Desktop.
D3 and Custom Data Attributes
license: gpl-3.0
<!DOCTYPE html>
<meta charset="utf-8">
<ul id="list">
<li data-username="shawnbot">Shawn Allen</li>
<li data-username="mbostock">Mike Bostock</li>
</ul>
<script src="//d3js.org/d3.v3.min.js"></script>
<script>
d3.selectAll("#list li")
.datum(function() { return this.dataset; })
.sort(function(a, b) { return d3.ascending(a.username, b.username); });
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment