Debug it. What, even
alert('Come here')
did not work? If you really copied all text correctly, it should work.
One possible problem is that you have lexical error elsewhere. In case of such error, the whole JavaScript, even correct fragment, may not work. JavaScript is not a pure interpreter (surprise?!), the implementation can have pre-processing where the lexical error can fail the whole thing without any exceptions.
First, of all, you can simplify all code down to some absolute minimum and make sure
onclick
handler does work. It will. Then, you can take different routes. First of all, use JavaScript debugger. If it seems to be difficult (there are problems with different set-ups), you can try to add code back by small pieces, until the problem re-appears. This is a hard way to localize it. If that seems to be difficult, I have my own "secret weapon": put all code in string use JavaScript
eval
on this string, sandwiched with try-catch block. This is a trick to catch lexical errors as exceptions, not only "usual" exceptions. I described this technique in detail in this section of my article:
JavaScript Calculator, 5. Handling Lexical Errors.
[EDIT: In response to the discussions in comments]
What are you talking about? This is a minimal code, it works:
<html>
<head>
<title>Click handler should work!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script>
function clickHandler() {
alert('click handler works!')
}
</script>
</head>
<body>
<img src="nothing certain" onclick="clickHandler()" width="100", height="100" />
</body>
</html>
So, you cannot tell us that
onclick
doesn't work. Start with this code sample and add your code. Or show your complete code (minimize it as much as your can). You are doing something wrong on some elementary level. Maybe script is misplaced (where is it?) maybe you misspell something. Analyze the situation on a comprehensive way.
—SA