Answers for "how to button in javascript"

2

how to create a button with javascri[t

// 1. Create the button
var button = document.createElement("button");
button.innerHTML = "Do Something";

// 2. Append somewhere
var body = document.getElementsByTagName("body")[0];
body.appendChild(button);

// 3. Add event handler
button.addEventListener ("click", function() {
  alert("did something");
});

/* Read 

https://css-tricks.com/use-button-element/
*/
Posted by: Guest on April-20-2021
0

button in javascript

<!DOCTYPE html>
<html>
<body>

<h2>Example of button </h2>
<p>This is the example of a button clickon it</p>

<button type="button" onclick="document.write(80+20)">click on me</button>

</body>
</html>
Posted by: Guest on July-09-2021

Code answers related to "how to button in javascript"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language