title: adding onclick event to dynamically added button?
body: <p>I am adding a button dynamically in html like below:
  On click of that button I want to call a Javascript function:</p>
  
  <pre><code>var but = document.createElement("button");
  
  but.value="delete row";
  
  but.setAttribute("onclick","callJavascriptFunction()");
  //this is not working
  
  but.onclick="callJavascriptFunction()"
  //this is also not working
  
  document.getElementById("but").onclick="callJavascriptFunction()"
  //this is also not working
  
  but.id="but"+inc;
  </code></pre>
  
  <p>Are there any ways to resolve this??Plz help me.,
  thanks in advance</p>