Today I’ll be super busy preparing the order of a true legend — @Joseinnewworld, who just swept around 58 #NFTs 😳🔥 That’s insane support… looks like I’ll be pulling an all-nighter to get everything ready 😅🙌 #NFT #NFTCollection #NFTCollectors #eCash $XEC #CryptoMevXBOT https://t.co/5iHxVEGjRo pic.twitter.com/xjpvlw34L6
— NFToa (@nftoa_) August 19, 2025
I have some JavaScript code in an HTML page with a button. I have a function called click() that handles the onClick event of the button. The code for the button is as follows:
<input type="button" onClick="click()">button text</input>The problem is when the button is clicked, the function is not called. What am I doing wrong here?
Solutip
You need to make a slight revision to the following code:
<input type="button">button text</input>Become:
<input type="button" value="button text" />You should rename your function. The function click() is already defined on the button (simulating a click), and has higher priority than your method.
Note that some of the advice here is wrong, and you shouldn't spend much time on it:
- Don't use
onclick="javascript:myfunc()". Only use the javascript: prefix insidehrefthe hyperlink: attribute<a href="javascript:myfunc()">. - You don't have to end with a semicolon.
onclick="foo()"andonclick="foo();"both work fine. - Event attributes in HTML are not case sensitive, so onclick, onClick and ONCLICK all work. It is common practice to write the attribute in lower case: onclick. note that javascript itself is case sensitive, so if you write
document.getElementById("...").onclick = ...,then it should be all lower case.
