• 0

javscript/jsfiddle help


Question

I've been learning javascript and today I thought I'd use jsfiddle to practise on since its quick and easy. but nothing I did was working properly, so I stripped back my code and just did a simple hello world alert on button click. Even that doesnt work!

I'm pretty confident my code is correct but it wont work. Is it jsfiddles fault or mine?

http://jsfiddle.net/JGuth/SmaAM/

That is with the javascript in the javascript box.

If i put the javascript in <script> tags then into the HTML it works then :s As you can see here: http://jsfiddle.net/JGuth/SmaAM/1/

The two are the exact same to my knowledge. So whats going on

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

By default JSFiddle doesn't add functions to the global/window scope, it wraps them inside an anonymous function, e.g:

<script type='[url=""]text/javascript[/url]'>//<![CDATA[
window.addEvent('load', function() {
function myFunction() {
alert("Hello World!");
}
});//]]> [/CODE]

If you choose "No wrap (head)" instead of "onLoad" under the framework section (in the sidebar) it will work as expected.

http://jsfiddle.net/SmaAM/2/

Link to comment
Share on other sites

  • 0

By default JSFiddle doesn't add functions to the global/window scope, it wraps them inside an anonymous function, e.g:

<script type='[url=""]text/javascript[/url]'>//<![CDATA[
window.addEvent('load', function() {
function myFunction() {
alert("Hello World!");
}
});//]]> [/CODE]

If you choose "No wrap (head)" under framework section (sidebar) it will work as expected.

thank you :)

I tried it here: http://jsbin.com/welcome/61091/

and it worked, couldn't understand what was going wrong.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.