quano
quano

Reputation: 19152

html js - onclick not working

I usually don't use onclick, but was gonna do some debug coding for an entirely different purpose, when I bumped into this problem. Am I completely blind, or why doesn't this work?

<html>
<head>

<script type="text/javascript">
function click()
{
    alert("hey");
}
</script>

</head>

<body>

<!-- Will not work in any browser -->
<input type="button" onclick="click()" value="click me" />

<!-- Will not work in IE -->
<a href="#" onclick="click()">click me</a>

<!-- Works in all -->
<input type="button" onclick="alert('hey')" value="click me" />
<a href="#" onclick="alert('hey')">click me</a>

</body>
</html>

Upvotes: 1

Views: 568

Answers (2)

Kyle Gagnon
Kyle Gagnon

Reputation: 62

I think you should try this and see if it helps: <input type="button" onclick="click()" value="click me"> You should get rid of the slash at the end. That is wat probaly is doing it. Hope it helps!

Upvotes: 0

pleasedontbelong
pleasedontbelong

Reputation: 20102

"click" is not a good name for a JS function, specially for IE

chenge the name of your function and let's all be happy =D

Upvotes: 3

Related Questions