title: Onclick-function on elements in Handlebars-template
body: <p>I'm building a simple webapp with just Handlebars.js and some jQuery.</p>
  
  <p>Now I have a list of data, and i present them through a Handlebars-template. Then I want some actions associated with these, e.g. update one element, or delete one. I have buttons that one associates with these actions, the problem is that I cannot manage to get <code>onclick</code>-methods associated with buttons in the template to work.</p>
  
  <p>I read <a href="https://stackoverflow.com/questions/10232574/handlebars-js-parse-object-instead-of-object-object">this question and answer</a>, which lead me to adding the extra bracket and helpermethod, but it still doesn't work. See code below.</p>
  
  <pre><code>Handlebars.registerHelper('json', function(context) {
      return JSON.stringify(context);
  });
  
  var myGreatFunction = function(someValue) {
      // Work with that value 
  }
  </code></pre>
  
  <p>The template:</p>
  
  <pre><code>{{#each Something}}
      &lt;button onclick="myGreatFunction({{{json this}}})"&gt;&lt;/button&gt;
  {{/each}}
  </code></pre>
  
  <p>Now, doing it like this give me <code>Uncaught SyntaxError: missing ) after argument list</code> at the top of the HTML-file.</p>
  
  <p>I noted the answer <a href="https://stackoverflow.com/questions/22659961/onblur-function-call-in-handlebar-template">here</a>, so I tried with <code>onclick="myGreatFunction( '{{{json this}}}' )"</code> which gives me the error <code>Uncaught SyntaxError: Unexpected token ILLEGAL</code> at the end of HTML-file.</p>
  
  <p>With <code>onclick="myGreatFunction( '{{json this}}' )"</code> the button simply disappears on click.</p>
  
  <p>Does anyone see something I've missed, or is there another way of doing this? I thought of adding the object to some div/button in the template, then add a jQuery-listener for the click that fetches the value from the template, but that seems so ugly and unclear.</p>
  
  <p>Any tips? All help is greatly appreciated - thanks in advance.</p>
  
  <p><strong>UPDATE:</strong> Seems the problem is, as Hacketo mentioned below, that the outputted JSON is kind of messed up. I inspected an element in my code:</p>
  
  <pre><code>onclick="someFunc('{&amp;quot;id&amp;quot;:5,&amp;quot;publisher&amp;quot;:null,&amp;quot;message&amp;quot;:&amp;quot; asdadsad&amp;quot;,&amp;quot;address&amp;quot;:&amp;quot;asdad&amp;quot;,&amp;quot;published&amp;quot;:&amp;quot
  Last Saturday at 12:00 AM&amp;quot;,&amp;quot;createdAt&amp;quot;:&amp;quot;2015-07
  23T09:55:35.486Z&amp;quot;,&amp;quot;updatedAt&amp;quot;:&amp;quot;2015-07-23T09:55:35.486Z&amp;quot;}')"
  </code></pre>
  
  <p>(Broken over multiple lines for your convenience).</p>
  
  <p>Now I just have to find out of to get that JSON to look right.</p>