So, I've seen this question kind of being answert. However in those cases, the one who asked had type="module" (while importing the javaScript file) and didn't mind to remove it. But I need to leave it module since I use import/export in other places. One recommendation was to import the JavaScript file twice, once with type=module and once without. that disabled my module import.
Is there a way to call a JavaScript function (in an onclick event listener) while importing my file as a module?
function drawAndMove(){
ctx.clearRect(0, 0, canvas.width, canvas.height);
audi.draw();
audi.move();
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="module" src="compare.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<input type="text" value="nix" id="farbId">
<button type="submit" id="subId" onclick="drawAndMove()">sub</button>
<main>
<canvas id="canvas" width="800" height="600">
</canvas>
</main>
</body>
</html>
onclick="drawAndMove()"will look for a function nameddrawAndMoveon the "global" object ... i.e.windoworglobalThis(same thing) - so - the function needs to be "put" there, by you