I am trying to use d3.select to create a button in the DOM with an onclick attribute so that when I click on the button, some function is called. However, before I click on the button, the function just calls itself. Here is my JS code:
var something = function() {
console.log("do something");
}
d3.select("#done")
.append("button")
.text("Button Text")
.attr("onclick", something);
and here is my HTML (there's more than this but this is the relevant part):
<div id="done"></div>
When I execute the code, the something function is immediately called and prints to the console. How can I fix this?
Apologies in advance if this seems really naive--I am very new to this.