const loginInput = document.querySelector("#login-form input");
const loginButton = document.querySelector("#login-form button");
function onLoginBtnClick() {
const value = loginInput.value;
if (value === "") {
alert("Please write your name.");
}
}
loginButton.addEventListener("click", onLoginBtnClick);
It's JS code.
I keep getting "Uncaught TypeError: Cannot read properties of null (reading 'addEventListener')" error. I'm trying to make a site that displays the username in the console window when I enter the username and click the login button.
I tried to change the code in line 1~2 as below.
const loginForm = document.getElementById("#login-form");
const loginInput = loginForm.querySelector("input");
const loginButton = loginForm.querySelector("button");