0

what on earth is wrong with this? http://jsfiddle.net/sVT54/

<button onclick="myFunction()">Click me</button>

<p id="demo"></p>
    function myFunction()
{
document.getElementById("demo").innerHTML="Hello World";
}
user3191137
  • 135
  • 3
  • 11
  • Your wrong Bergi. That has the same answer, not the same question. I did not know that JSfiddle was the culprit. You can't fault me for not finding that before posting. – user3191137 Feb 20 '14 at 16:07
  • 1
    It's the exact same question and answer – Ian Feb 20 '14 at 16:08
  • If it was the same question or even similar, my question would be "JSfiddle is not working with my code". I thought my problem WAS my code. If I knew the problem was JSfiddle I would've found that answer. – user3191137 Feb 20 '14 at 16:11
  • "*What on earth is wrong*" is not a good question actually. I'm not faulting you, I'm just giving you a hint. And it should be closed as a dupe when the problem is the same, even if you didn't ask about the problem. – Bergi Feb 20 '14 at 16:11

2 Answers2

4

JSFiddle wraps your javascript code in the onLoad call of the page by default so myFunction is defined only in that function's scope. Change to No wrap - in <head> and your code will run as expected.

no wrap

http://jsfiddle.net/sVT54/3/

dee-see
  • 23,668
  • 5
  • 58
  • 91
0

include your JavaScript in

<Script>
 function myFunction()
 {
    document.getElementById("demo").innerHTML="Hello World";
 }
</script>
Aftab Ahmed
  • 1,727
  • 11
  • 15