Im struggled now with JS again.
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>ATM Interfacetest</title>
<script>
class Test{
constructor(){
this.name = 'heinz';
}
testwindow(){
var tmp = document.createElement('button');
tmp.id = 'idtest';
tmp.className = 'test';
tmp.onclick = this.test;
tmp.innerHTML = 'Klick mich';
document.body.appendChild(tmp);
}
test(){
alert(this.name);
}
}
function e(){
var i = new Test();
i.testwindow();
// Testcall
i.test();
}
</script>
</head>
<body onload="e();">
</body>
</html>
Calling the method test from e() with onload in the body-tag works pretty fine.
Calling the method the button brought to the document, doesn't work. Reading out this.name is not possible. The alert-window remains empty.
As i am used to code like this from python, is JS following other principles?
Or how can i call the function from the button. At least it works fine, i can't get the issue by myself.
Calling