title: Inject html using Javascript
body: <p>I have to inject the following line of html to a document through javascript:</p>
  
  <pre><code>&lt;button type='button'&gt;btnName &lt;/button&gt;
  </code></pre>
  
  <p>In addition to this, I have to register an onclick to the button where the function to be invoked expects an arg say <code>'arg'</code> so the javascript looks something like this:</p>
  
  <pre><code>var html = "&lt;button type='button' onclick='+ fnName +
      "(the param shld go here)'&gt;" + btnName + "&lt;/button&gt;"
  </code></pre>
  
  <p>How do I achieve this?
  One obvious solution is to assign an Id to the button and then register a click function later on once the html is appended to the document. But I dont want to do this because there are too many buttons. Is there another option that you can think of.</p>
  
  <p><strong>Addition:</strong>
  The function name is dynamic, and the <code>'arg'</code> that goes in is also dynamic. An Id if at all is required has to be autogenerated.</p>
  
  <p>**</p>
  
  <blockquote>
    <p>I've got the solution, please see below</p>
  </blockquote>
  
  <p>**</p>