When using javascript with the type onload, it will generate the script at the beginning of your jsfiddle like this:
window.onload=function(){
function myclick(){
alert("myclick");
}
}
<YourHTML>
The issue lies in the fact that myclick() is not recognized because it is created after the HTML and is not triggered with onload. To resolve this, you can refer to this jsfiddle: https://jsfiddle.net/cqL9t8mh/1/
In the solution provided, you should remove onclick="myclick" from the button and replace it with an ID 'btnToggle'. Then, in the javascript section, add an event listener of type click on the ID 'btnToggle' to invoke your myclick function.
Furthermore, addressing the query mentioned in the prior answers, please visit:
https://i.sstatic.net/b6TY5.png
This adjustment will result in the following code structure:
<YourHTML>
function myclick(){
alert("myclick");
}
Now, your HTML is constructed before your function, eliminating the need for onload, thereby enabling the function to trigger every time you click the button.