Search code examples
javascriptjsfiddle

Why is defined method not being recognized in jsfiddle?


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>

Solution

  • Change the wrap setting in javascript.

    enter image description here