XHTML » XHTML Core Tag » onclick

Syntax:
onclick="action"

The onclick event is associated with the single click of a mouse on a selected HTML tag (element). Whenever you single click the element, the script code of the onclick is executed. This script can also call functions or subroutines which contain code that you want to run when the single click occurs.

The similar ondblclick event is associated with the double click of a mouse.

Examples

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>DevGuru XHTML onclick Tag Example</title>
</head>
<body>
<input type="button" onclick="JavaScript: alert( 'onclick event' )" value="Click On This Button" />
</body>
</html>
Output:
Explanation:

In this example, every time you single click on the button element, one line of JavaScript code is executed which causes an alert box to be displayed with a message.

Language(s): XHTML

See Also: