HTML DOM click() method

HTMLWeb DevelopmentFront End Technology

The HTML DOM click() method simulates a mouse-click on an element. It can be used to click on any element just like a user would do. This is used to fire the elements click event. The click event does event bubbling i.e. it will execute the click event of all its parents too.


Following is the syntax of HTML DOM click() method −


Let us see an example for the click() method −

<!DOCTYPE html>
<p>Hover over the radio button to simulate a mouse-click.</p>
<label>Radio <input type="radio" id="myRadio" name="choice"
<p id="Sample"></p>
   function clickFunction() {
      document.getElementById("Sample").innerHTML = "Radio button has been clicked on
      mouse hover";


This will produce the following output −

On hovering over the radio button −

We have created a radio button with label inside a form and gave it the “myRadio” id. This button on mouse hover will execute the clickFunction() −

<label>Radio <input type="radio" id="myRadio" name="choice" onmouseover=”clickFunction()"</label>

The clickFunction() using getElementById() method gets the radio button and executes its click() method. This will check the radio button . After checking the radio button a success message is displayed in the paragraph with id “Sample” using its innerHTML property −

function clickFunction() {
   document.getElementById("Sample").innerHTML = "Radio button has been clicked on mouse hover";
Updated on 07-Aug-2019 13:14:24