d3 / d3-selection

Transform the DOM by selecting elements and joining to data.

Home Page:https://d3js.org/d3-selection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The contents of i and d are reversed in handling events callback function

Tyxiang opened this issue · comments

<!DOCTYPE html>
<html class="no-js">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
  <title>about</title>
  <script src="./d3.min.js"></script>
</head>

<body>
  <svg id="svg" version="1.1" xmlns="http://www.w3.org/2000/svg"></svg>
  <script>
    var data = "abc".split("");
    d3.select("body").selectAll("text")
      .data(data)
      .enter()
      .append("p")
      .text(function (d) { return d; })
      .on("click", function (d, i) {
        console.log(i);
      })
  </script>
</body>

</html>

a/b/c will be output.