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>
        <title>Wikitechy onclick  attribute</title>
        <p onclick="onClick()">Click Here!</p>
        function onClick() 
            alert('Welcome to Wikitechy!');

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

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add to your ad blocking whitelist or disable your adblocking software.