Make a Button with Newly Made Id
<html><head>
<title>Make a Button with newly made id</title>
<script>
function myButton()
{
let theButton = document.createElement("Button");
theButton.innerHTML = "My created button";
document.body.appendChild(theButton);
var theNewId = document.createAttribute("id");
theNewId.value = "myFirstButtonId";
theButton.attributes.setNamedItem(theNewId);
}
</script>
<body>
<button onclick="myButton()"> Make a Button </button>
</body>
</html>
<title>Make a Button with newly made id</title>
<script>
function myButton()
{
let theButton = document.createElement("Button");
theButton.innerHTML = "My created button";
document.body.appendChild(theButton);
var theNewId = document.createAttribute("id");
theNewId.value = "myFirstButtonId";
theButton.attributes.setNamedItem(theNewId);
}
</script>
<body>
<button onclick="myButton()"> Make a Button </button>
</body>
</html>