0

so I have been working with jupyter notebook using python3, and I ran into a problem that I have seaching the internet for so many hours trying to figure out. The problem is why does this

from ipywidgets import HTML

HTML('''<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
    document.getElementById("demo").innerHTML = "Hello World!";
}
</script>

</body>
</html>''')

produce an error in the console

Uncaught ReferenceError: myFunction is not defined at HTMLButtonElement.onclick (testing.ipynb:1)

however it works fine whenever I inline the functions, as such

from ipywidgets import HTML

HTML('''<!DOCTYPE html>
<html>
<body>

<button onclick='document.getElementById("demo").innerHTML = "Hello World!";'>Try it</button>

<p id="demo"></p>

</body>
</html>''')

Is it just not work on my machine? Or does this somehow not work due to the wrapping that python does?
Does anyone have any idea why this does not work? Thanks in advance.

Albatross
  • 3
  • 1
  • 3

0 Answers0