Uncaught TypeError: Cannot set properties of null (setting 'onclick') at index.html:19:44


<!DOCTYPE html>
<script>
var websocket = new WebSocket("ws://localhost:9999/");
websocket.onopen = function(){
    console.log('websocket open')
    document.getElementById('recv').innerHTML = 'Connected'
}
 
websocket.onclose = function(){
    console.log('websocket close')
}
 
//sending message from front to back
websocket.onmessage = function(e){
    console.log("This is on message data: " + e.data)
    document.getElementById('recv').innerHTML = e.data
}
 
document.getElementById('sendBtn').onclick = function(){
    var username = document.getElementById('username').value
    var password = document.getElementById('password').value
    websocket.send(username+";"+password)
}
</script>
<html>
<h1>Echo Test</h1>
    Username: <input id="username" type="text">
    <br>
    Password: <input id="password" type="text">
    <br>
    <button id="sendBtn">SEND</button>
<div id='recv'></div>
</html>

Uncaught TypeError: Cannot set properties of null (setting 'onclick')
at index.html:19:44