JsFiddle not working in Chrome
I recently created a fiddle with the following code -
HTML
<button onclick="action();">click me<img src="http://dummyimage.com/200x200/000000/fff.gif&text=Image+1" width="200px" id="ImageButton1"></button> Js
function action ( ) { if(document.getElementById("#ImageButton1").src == 'http://dummyimage.com/200x200/000000/fff.gif&text=Image+1' ) document.getElementById("#ImageButton1").src = 'http://dummyimage.com/200x200/dec4ce/fff.gif&text=Image+2'; else document.getElementById("#ImageButton1").src = 'http://dummyimage.com/200x200/000000/fff.gif&text=Image+1'; } Link to the script - http://jsfiddle.net/QVRUG/4/
This code works in FF and in the local html file, but throws an error in the chrome console -
Uncaught ReferenceError: action is not defined Next, I investigated the error and found -
Unused ReferenceError for function defined in onload function
So I tried too -
window.action = function(){...code here...}; But no luck :(
Please let me know about this behavior, why it doesnβt work in Chrome and works for others. Please do not just specify the patch to make the violin work, as I am also interested in the behavior. The descriptive answers (with the appropriate link for further study) are really appreciated in this case so that I can move correctly in my other projects.
Let me know if the question is not on the track, I will remove it (although I have made my honest efforts to make the question clean and understandable)
This is because the "language" is set as Javascript 1.7 in jsFiddle.
Why does this only work in Firefox?
According to version history , 1.7 was only supported in Mozilla Firefox, so why it works there and not in other browsers.
Decision:
Change the language from Javascript 1.7 to Javascript in the Languages section of your jsFiddle and it will work. I assume that you must have changed it to 1.7, because the default is usually just Javascript (you can see this by pasting your code into a new jsFiddle where it will work as expected).