I have to inject the following line of html to a document through javascript:
<button type='button'>btnName </button>
In addition to this, I have to register an onclick to the button where the function to be invoked expects an arg say 'arg'
so the javascript looks something like this:
var html = "<button type='button' onclick='+ fnName +
"(the param shld go here)'>" + btnName + "</button>"
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.
Addition: The function name is dynamic, and the arg that goes in is also dynamic. An Id if at all is required has to be autogenerated.
**
Ive got the soltion, please see below
**