Answers for "new button()"

6

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

how to use <button>

<!DOCTYPE html>
<script>
function log() {
console.log("Hello World!")
}
</script>
<html>
	<button onclick="log()">Button</button>
</html>
Posted by: Guest on January-15-2022

Browse Popular Code Answers by Language