Uncaught ReferenceError: <function> not defined in HTMLButtonElement.onclick

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

HTML code

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

Js code

 function hideButton(){ $(".loading").hide(); } function showButton(){ $(".loading").show(); } 

I am showing a spinner, and I would like the spinner to hide when I click the Hide button. I get the following error:

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

Can anyone suggest a solution?

thanks

Sechin

+13
source share
2 answers

Put your script in the body tag

 <body> // Rest of html <script> function hideButton() { $(".loading").hide(); } function showButton() { $(".loading").show(); } </script> < /body> 

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

+1
source

The same thing that I had ... I wrote the whole script in a separate file and added it through the tag to the end of the HTML file after the body tag. After moving the tag inside the body tag, it works fine. before:

 </body> <script>require('../script/viewLog.js')</script> 

after:

 <script>require('../script/viewLog.js')</script> </body> 
-one
source

Source: https://habr.com/ru/post/1013514/


All Articles