I'm testing some javascript on jsfiddle and for some reason I can't get a function to fire on a button click. Any advice?
Asked
Active
Viewed 2.4k times
43
-
click the JsLint button and you will see coding errors – Nicholas Murray Feb 02 '12 at 15:17
-
missing ) after argument list }); /_display/ (line 66, col 4) You have js errors. – Feb 02 '12 at 15:20
-
1I would also suggest that you use a framework like Backbone.js. You can create a 'Room' model and set its attributes - like price and room number. Then push those models into a Collection (sort of like a super-array that has some helpful methods). You can use it with JQuery and it would really help clean up your code. – PhillipKregg Feb 02 '12 at 15:30
2 Answers
128
In the Frameworks & Extensions
panel, set onLoad
to No wrap - in <body>
.
It took me a while to figure this out.

dk123
- 18,684
- 20
- 70
- 77
-
1awesome! Can you explain what exactly this does? what does wrap mean with regards to onLoad()? – Sujay Phadke Feb 11 '16 at 00:23
-
4
-
5Click on the settings icon next to JAVASCRIPT in the JAVASCRIPT panel and choose 'no wrap - in ' – Martlark Nov 30 '16 at 01:04
18
You have configured JSFiddle to wrap the code in an onload event handler. Consequently the function you are trying to call onclick
is out of scope.
Don't use intrinsic event attributes. Use jQuery's (since you are using jQuery already) event binding instead.

Quentin
- 914,110
- 126
- 1,211
- 1,335
-
1Although the above answer tells us how to fix the issue, I upvote yours because you explain what is going on :) – Maria Ines Parnisari Dec 01 '14 at 05:17