I created one button dynamically in JavaScript and I am unable to set action for that button..
var but = document.createElement("input");
but.type = "button"
but.value = "NewButton";
but.onClick = check();
var newElement = document.getElementById("addButton"); //span element id
newElement.appendChild(but);
The function ‘check()’ is not called when button is clicked
You have 2 problems with your code. The first is that the event is not capitalized, the second is that you want to assign the event to the function rather than the results of the function. It should look like:
This will actually assign the event to the address of the function rather than the expected result of the function (which would do nothing).