Make a Button with a New Onclick Event
<html><head>
<title>Make a Button with a New Onclick Event </title>
<script>
function myButton()
{
let theButton = document.createElement("Button");
theButton.innerHTML = "My created button";
document.body.appendChild(theButton);
var theNewId = document.createAttribute("onclick");
theNewId.value = "myButton()";
theButton.attributes.setNamedItem(theNewId);
}
</script>
<body>
<button onclick="myButton()"> Make a Button </button>
</body>
</html>
<title>Make a Button with a New Onclick Event </title>
<script>
function myButton()
{
let theButton = document.createElement("Button");
theButton.innerHTML = "My created button";
document.body.appendChild(theButton);
var theNewId = document.createAttribute("onclick");
theNewId.value = "myButton()";
theButton.attributes.setNamedItem(theNewId);
}
</script>
<body>
<button onclick="myButton()"> Make a Button </button>
</body>
</html>