Uncaught ReferenceError: is not defined at HTMLButtonElement.onclick [duplicate]

I have created my problem on JSFiddle at https://jsfiddle.net/kgw0x2ng/5/. The code is as follows


<div class="loading">Loading&#8230;</div> 
<button type="submit" onClick="hideButton()">Hide</button>
<button type="submit" onClick="showButton()">Show</button>


function hideButton(){
function showButton(){

I am showing a spinner and I would like the spinner to hide when I click on the “Hide” button. I am getting the following error :

Uncaught ReferenceError: showButton is not defined
    at HTMLButtonElement.onclick (VM282:180)
onclick @ VM282:180

Uncaught ReferenceError: hideButton is not defined
    at HTMLButtonElement.onclick (VM282:179)
onclick @ VM282:179.

Can someone please suggest a solution?



Place your script inside the body tag

  // Rest of html
  function hideButton() {
function showButton() {
< /body>

If you check this JSFIDDLE and click on javascript, you will see the load Type body is selected

Same Problem I had… I was writing all the script in a seperate file and was adding it through tag into the end of the HTML file after body tag.
After moving the the tag inside the body tag it works fine.
before :


after :


The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .
Read More:   Selecting an element in iframe with jQuery

Similar Posts