Answers for "create element button"

2

creating a button in html

<!-- html button tag example -->
<button type="button">Click Me!</button>

<!-- html example code for button -->
<html>
  <head>
    <title>Example Button Code</title>
  </head>
  
  <body>
    <button onclick="buttonFunction()">Click Me!</button>
    
    <script>
      function buttonFunction() {
        console.log("This function is called when the button is pressed");
      }
    </script>
    
  </body>
</html>
Posted by: Guest on September-25-2021
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
16

jquery create element

var newDiv = $('<div>My new div</div>');  //create Div Element w/ jquery
$( "#someOtherElement" ).append(newDiv); //append new div somewhere
Posted by: Guest on August-02-2019

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language