freeCodeCamp Challenge Guide: Update the Height of an Element Dynamically

Update the Height of an Element Dynamically


Solutions

Solution 1 (Click to Show/Hide)
<style>
  .bar {
    width: 25px;
    height: 100px;
    display: inline-block;
    background-color: blue;
  }
</style>
<body>
  <script>
    const dataset = [12, 31, 22, 17, 25, 18, 29, 14, 9];
    d3.select("body").selectAll("div")
      .data(dataset)
      .enter()
      .append("div")
      .attr("class", "bar")
      .style('height', d => `${d}px`)
  </script>
</body>
8 Likes