title: Dynamic onclick inside attr?
body: <p>I want dynamically create a set of buttons generated by a list of strings:</p>
  <pre><code>keys = [ &quot;Temp_Innen&quot;, &quot;Temp_Außen&quot;, &quot;Druck&quot;, &quot;Feuchte_Innen&quot;, &quot;Feuchte_Außen&quot;, &quot;PH10&quot;, &quot;PH25&quot; ]
  </code></pre>
  <p>Those strings shall also be used in each button on the onClick event function(parameter)...</p>
  <p>I use this to create the buttons inside the body:</p>
  <pre><code>d3.select('body')
    .selectAll('button')
    .data(keys)
    .enter()
    .append('button')
    .text(d =&gt; d)
    .attr('type', 'button');
  </code></pre>
  <p>Which gives me nice buttons:
  <a href="https://i.stack.imgur.com/S0FTw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/S0FTw.png" alt="enter image description here" /></a></p>
  <p>But how can I add dynamically add each string into an function parameter that is called via onClick? I tried this but it doesnt work:</p>
  <pre><code>.attr('onClick',`clicked(${d =&gt; d})`);
  </code></pre>
  <p>But that does not write the strings into the clicked() parameter, instead its written unexpressed as text:</p>
  <pre><code>&lt;button type=&quot;button&quot; onClick=&quot;clicked(d =&gt; d)&quot;&gt;Temp_Innen&lt;/button&gt;
  &lt;button type=&quot;button&quot; onClick=&quot;clicked(d =&gt; d)&quot;&gt;Temp_Außen&lt;/button&gt;
  ...
  </code></pre>
  <p>Is there a way to do that dynamically or should I consider writing all those buttons static in my html file?</p>