This works:
<div id="chart"></div>
<script>var svg = d3.select("#chart").append("svg:svg");</script>
This doesn't:
<script>var svg = d3.select("#chart").append("svg:svg");</script>
<div id="chart"></div>
I tried wrapping the code in a jquery document.ready(), grabbing the element with jquery, and passing it into d3.select, but that didn't work either. Edit Once I got the jquery document.ready() syntax right, it worked.
Any way I can include the javascript at the top of the page and still select an element below? Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…