Selectall Not Selecting Any Nodes On D3
I am trying to select 4 divs using a d3 selectAll function, but nothing is getting selected. The height in this code never changes: The select('#chart') works when it is used by
Solution 1:
The question was in d3.v3. Below snippet works for me.
d3.select('#chart').selectAll('.bar').style('height', '40px')
<!DOCTYPE html><htmllang="en" ><head><metacharset="utf-8"><scriptsrc="https://d3js.org/d3.v3.min.js"></script><style>.bar {
float: left;
width: 30px;
margin-right: 20px;
border-color: #F4F5F7;
border: 1px solid #C5C5C5;
}
#chart {
width: 100%;
height: 300px;
}
</style></head><body><divid="chart"><divclass="bar"></div><divclass="bar"></div><divclass="bar"></div><divclass="bar"></div></div></body></html>
Solution 2:
It was a timing issue. If I defer the scripts (so they run after everything has loaded and then runs them in order) like mentioned in the comments on my question, everything works:
<scriptsrc="https://d3js.org/d3.v3.min.js"defer></script><scriptsrc="./project1.js"defer></script>
Post a Comment for "Selectall Not Selecting Any Nodes On D3"