How to create dynamic button using javascript?


<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Create Button</title>
</head>
<body>
  <div id="root"></div>
</body>
<script>
  const root = document.getElementById("root");

  const button = document.createElement("button");

  const text = document.createTextNode("Click Me");
  
  button.append(text)
  root.append(button)

</script>
</html>
Reactions

Post a Comment

0 Comments