HTML:
<img src="https://help.pace.edu/helpdesk/info_icon_small.gif?v=12_1_0_300.gif" onclick="plusButton_Click()">
js:
function plusButton_Click() {
alert('hi');
}
I might be new to Javascript and all. But why does my Firefox console say
"ReferenceError: plusButton_Click is not defined"?
By default, jsFiddle places your Javascript code into an
onLoad
function. YourplusButton_Click
will not be visible outside of this closure.To fix, either:
<head>
" from the dropdown (Example)window.plusButton_Click = function() { ... }
(Example)Because the function must be in global scope if you intend to call it in inline js.
jsfiddle creates a new closure, so it is not global. Use their
--wrap it in head--
option.Updated demo
Or change
to:
You have javascript set to onLoad. In a normal page, you would have put it straight in the body most likely. Set it to NoWrap and it should work fine.