0

I have a very simple jsfiddle but it results in an error saying Uncaught ReferenceError: doSomething1 is not defined or Uncaught ReferenceError: doSomething2 is not defined. Both these methods are defined.

jsfiddle: https://jsfiddle.net/fjd4hzcz/3/

Question

What is wrong with this jsfiddle that is causing the methods to be not recognized?

My code is very simple as below.

<button id="btn1" onclick="doSomething1();return false;">Call doSomething1 method</button>

<button id="btn2" onclick="doSomething2();return false;">Call doSomething2 method</button>
<script>
function doSomething1() {
  alert("hi 1");
}

function doSomething2() {
  alert("hi 2");
}

</script>
Sunil
  • 20,653
  • 28
  • 112
  • 197

2 Answers2

1

Change the wrap setting in javascript.

enter image description here

alDiablo
  • 969
  • 7
  • 22
1

This is caused by including the javascript in jsfiddle. Please select the "No wrap - head" or "No wrap - body" in javascript settings in javascript window. Hoping it helps you.

Andrew Li
  • 1,005
  • 12
  • 29