add javascript to html button code example

Example 1: javascript onclick

document.getElementById("Save").onclick = function ()
    {
     alert("hello");
     //validation code to see State field is mandatory.  
    }

Example 2: how to add button in javascript

const button = document.createElement("button");
button.innerHTML = "Do Something";

Example 3: button click function in js

<script>
  $(document).ready(function(){
    $('#MyButton').click(function(){
       CapacityChart();
    });
  });
</script>

<input type="button" value="Capacity Chart" id="MyButton" >

Example 4: how to make a button in javascript

<button id="btn">button</button>