Why isn’t my JavaScript working in JSFiddle?

If you do not specify the wrap setting it defaults to “onLoad”. This results with all JavaScript being wrapped in a function run after result has been loaded. All variables are local to this function thus unavailable in the global scope.

Change the wrapping setting to “no wrap” and it’ll work:


I switched the framework to “No Library” as you don’t use any.

Leave a Comment