Question

In plain old HTML the following code will work:

<input type="button" value="click" onClick="function()" />

However; in XHTML Strict 1.0 this code will not validate, saying that "there is no function onClick". I know that this code here will work,

<a href="javascript:function()>click</a>

But I want the function to occur on the click of a button.

Was it helpful?

Solution

It's onclick (all lower case) in XHTML, which is case-sensitive. (Reference) So for instance (live copy):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>
<title>Testing</title>
<script type="text/javascript">
function foo() {
    alert("Hi there");
}
</script>
</head>
<body>
<p onclick="foo()">Testing</p>
</body>
</html>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top