Whenever I type into the <input />
element of my HTML, everything disappears. I din't see any problem or error on my JavaScript console, and when I inspect the page, the code seems to disappear as well.
Code:
<!DOCTYPE html>
<html>
<head>
<title>My Coding stuff</title>
</head>
<body>
<input type="text" id="myInput" onkeydown="write()" />
<p id="myDiv" style="width: window.innerWidth;" style="color: green;"></p>
<script>
function write() {
document.getElementById("myDiv").innerHTML += Math.floor(Math.random()*2) + " ";
document.getElementById("myInput").value = "";
}
</script>
</body>
</html>
Does anyone know why this is happening? Thanks