HTML attribute
This example assigns a function-reference to the
HTML attribute onclick
:
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<title>onclick</title>
<script type="text/javascript">
function clicked(elem) {
alert(elem + " was clicked");
}
</script>
</head>
<body>
<form action="#">
<input type="button" value="Click me!" onclick="clicked(this);">
</form>
<div style="background-color:yellow; width: 100px; height: 100px" onclick="clicked(this);">
Click me, too.
</div>
</body>
</html>