How to call a JavaScript function on click?

To call a function on click of a button in JavaScript, use onclick. Try to run the following code to call a function onclick in JavaScript −


         function sayHello() {
            document.write ("Hello there!");
      <p>Click the following button to call the function</p>

         <input type = "button" onclick = "sayHello()" value = "Say Hello">

      <p>Use different text in write method and then try...</p>