Sign in to follow this  
Followers 0

javscript/jsfiddle help

3 posts in this topic

Posted

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

Share this post


Link to post
Share on other sites

Posted

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!");

}

});//]]> 

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/

Share this post


Link to post
Share on other sites

Posted

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!");

}

});//]]> 

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.