what am I doing wrong? x.innerHTML is undefined as result.
How can I put the text, returned by d3.json in x? Thanks.
<tr>
<td>1</td>
<td id = "val">0.087</td>
<td>0.23</td>
<td>0.3</td>
</tr>
</table>
<script type="text/javascript" src=".v3.min.js" charset="utf-8">
</script>
<script type="text/javascript">
var x = d3.select("#val");
setInterval(function() {
d3.json("./cgi-bin/script1.sh", function(error, text){
if (error) return console.warn(error);
console.debug(text.date);
x.innerHTML = text.date;
})
}, 1000);
</script>
</body>
what am I doing wrong? x.innerHTML is undefined as result.
How can I put the text, returned by d3.json in x? Thanks.
<tr>
<td>1</td>
<td id = "val">0.087</td>
<td>0.23</td>
<td>0.3</td>
</tr>
</table>
<script type="text/javascript" src="http://d3js/d3.v3.min.js" charset="utf-8">
</script>
<script type="text/javascript">
var x = d3.select("#val");
setInterval(function() {
d3.json("./cgi-bin/script1.sh", function(error, text){
if (error) return console.warn(error);
console.debug(text.date);
x.innerHTML = text.date;
})
}, 1000);
</script>
</body>
Share
Improve this question
asked Aug 5, 2015 at 7:36
Иосиф СталинИосиф Сталин
1471 gold badge3 silver badges7 bronze badges
1
- when do you access the x.InnerHTML? Perhaps you are accessing it before it gets updated? – Adam Moszczyński Commented Aug 5, 2015 at 7:40
1 Answer
Reset to default 16Your x is not a native dom element, it's a dom element wrapped by d3 and therefore does not possess the .innerHTML attribute.
Either use a d3 method to do it :
x.html(text.date)
Or get the original node and use innerHTML
x.node().innerHTML = text.date