You are here: Reference > HTML > attributes > event (script)

event attribute (script)

Browser support:
Sets an event that the script element should listen for.
Use it together with the for attribute that specifies the source object of the event. For a cross-browser solution use inline event attributes. See Example 2 for details.
JavaScript page for this attribute: event. You can find other example(s) there.

Possible values:

String that sets the name of the event. For a complete list of events in HTML, see the page for events.
Default: this attribute has no default value.

Example HTML code 1:

This example illustrates the use of the event attribute:
<head>
    <script type="text/javascript" for="myButton" event="onclick">
        alert ("You have clicked on the button.");
    </script>
</head>
<body>
    <button id="myButton">Sample button</button>
</body>
Did you find this example helpful? yes no

Example HTML code 2:

This example is equivalent to the previous one, but it uses inline event handling to listen the event:
<head>
    <script type="text/javascript">
        function OnButtonClick () {
            alert ("You have clicked on the button.");
        }
    </script>
</head>
<body>
    <button onclick="OnButtonClick ();">Sample button</button>
</body>
Did you find this example helpful? yes no

Supported by tags:

External links:

User Contributed Comments

Post Content

Post Content