Create a button with text:
Click the button to make a BUTTON element with text.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <script> function myFunction() {//from w w w .j ava2 s. c o m var btn = document.createElement("BUTTON"); btn.innerHTML = "CLICK ME"; document.body.appendChild(btn); } </script> </body> </html>
The createElement()
method creates an Element Node with the specified name.
document.createElement(nodename);
Parameter Values
Parameter | Type | Description |
---|---|---|
nodename | String | Required. The name of the element you want to create |
The createElement()
method returns an Element object representing the created Element node.