Javascript code please help

let searchBtn = document.querySelector(‘#search-btn’);
let searchBar = document.querySelector(‘.search-bar-container’);
let formBtn = document.querySelector(‘#login-btn’);
let loginForm = document.querySelector(‘.login-form-container’);
let formClose = document.querySelector(‘#form-close’);

window.onscroll = () => {
searchBtn.classList.remove(‘fa-times’);
searchBar.classList.remove(‘active’);
};

searchBtn.addEventListener(‘click’, () => {
searchBtn.classList.toggle(‘fa-times’);
searchBar.classList.toggle(‘active’);
});

formBtn.addEventListener(‘click’, () => {
loginForm.classList.add(‘active’);
});

formClose.addEventListener(‘click’, () => {
loginForm.classList.remove(‘active’);
});

Please help me this code does not run

That error means that the variable formClose is null and thus you can’t add an event listener to it.

Are you sure you have an element with the id of form-close?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.