html tutorial - onclick Attribute in HTML - html5 - html code - html form



onclick Attribute in html

Learn html - html tutorial - onclick Attribute in html - html examples - html programs

  • The onclick attribute trigger an event on a mouse click on the element.
  • The onclick attribute is a section of the Event Attributes.

Syntax for onclick attribute in HTML:

<element onclick="script">

Applies To:

Element Attribute
All HTML Elements onclick

Attribute Values:

Value Description
script The script to be run on onclick.

Sample Coding for onclick Attribute in HTML:

Tryit<!DOCTYPE html>
<html>
        <head>
        <title>Wikitechy onclick  attribute</title>
        </head>
 <body>
        <p onclick="onClick()">Click Here!</p>
        <script>
        function onClick() 
        {
            alert('Welcome to Wikitechy!');
        }
        </script>
</body>
</html>

Code Explanation for onclick Attribute in HTML:

onclick  Attribute Code Explanation

  1. The onclick attribute is used to call JavaScript function “onClick()” when the user click over “Click Here!” .
  2. onClick() JavaScript function is used to display an alert box.

Output for onclick Attribute in HTML:

onclick Attribute Tag Output

  1. The content Click Here! has been displayed when the page loaded.
  2. onclick1 Attribute Tag Output

  3. When the user click over the text “Click Here!” alert box will be displayed on the screen.

Browser Support for onclick Attribute in HTML:

Yes Yes Yes Yes Yes

Tips and Notes


Related Searches to onclick Attribute in html