I am currently making a simple online text editor site. And I cannot detect backspace being pressed. Here is the code: HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="cssfile/style.css">
<title> Code Editor </title>
<script src="jsfile/main.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="navdiv"></div>
<div id="board" class="board">
</div>
</body>
</html>
js: This is my main code:
document.addEventListener("keypress", function (event) {
console.log(event.key)
if (event.key == "Enter") {
document.getElementById("board").innerText += '\n'
} else {
document.getElementById("board").innerText += event.key
}
});
This is my code and I tried
if(event.key == "Backspace")
But that didn't work.