HTML onclick attribute

HTML onclick attribute: In this attribute will trigger when the event on the mosue click changes. And this event is similar to the oninput event.

HTML onclick attribute

This attribute will support all parts of the HTML.

Syntax: <element onlick = “script”>



Browser compatibility

This attribute supports different types of browsers as follows

  • Chrome
  • Mozilla
  • InternetExplorer
  • Safari
  • Opera

Example:

<!DOCTYPE HTML> 
<html> 
    <head> 
        <title> 
            onclick event attribute 
        </title> 
        <script> 
          
            /* If onclick event call then 
            this script will run */ 
            function onclick_event() { 
                document.getElementById("freshersnow").innerHTML  
                    = "Welcome to Freshersnow!"; 
            } 
        </script> 
    </head> 
      
    <body style = "text-align:center"> 
          
        <!-- onclick event call here -->
        <p id = "freshersnow" onclick = "onclick_event()"> 
            Click Here 
        </p> 
    </body> 
</html>

Output:

html onclick attribute