Reputation: 8920
I am new to D3, I am trying various stuff to explore the library. I have the following button
and I want to change its text:
<button id="showhide" onclick="myFunction()">Show me the graph</button>
I tried various stuff like:
d3.select("showhide").html("asdsa");
d3.select("showhide").innerHTML("asdsa");
d3.select("showhide").text("asdsa");
but none of them works. I know how to do it using DOM or jQuery, I am wondering how to do it using D3js.
Upvotes: 2
Views: 3496
Reputation: 22882
Since you are trying to select the button
using its ID, you need to prepend '#'
to your selector:
d3.select("#showhide").text("asdsa");
If you'd rather, you can use D3 to add an event listener to the button
, e.g.
d3.select("#showhide").on("click", function(){
d3.select(this).text("asdsa");
});
See a JSfiddle demo here.
Upvotes: 6