Home >Web Front-end >JS Tutorial >Why Isn't My JavaScript Code Executing in JSFiddle?
JSFiddle JavaScript Code Not Executing
When attempting to execute JavaScript code within a JSFiddle, you may encounter an error that the function you are calling is not defined. This error typically occurs when the JavaScript code is added to the
section of the HTML document, while the HTML code is added to the section.Solution:
The default wrap setting in JSFiddle is "onLoad", which wraps all JavaScript code in a function that is executed after the result has been loaded. This wrapping creates a local scope for all variables, making them unavailable in the global scope.
To resolve this issue, change the wrap setting to "no wrap":
Example:
<input type="button" value="test" onclick="test()" /> <script> function test() { alert("test"); } </script>
After making these changes, the JavaScript code should now execute correctly when the button is clicked.
The above is the detailed content of Why Isn't My JavaScript Code Executing in JSFiddle?. For more information, please follow other related articles on the PHP Chinese website!