2

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.

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.