Hello! If you want to keep your app like that you have to create new function to remove unnecessary errors and attach it to your listener.
const removeErrorMessage = () => {
const errorElements = document.querySelectorAll('.invalid-message');
if (errorElements.length === 0) return;
errorElements.forEach(error => {
error.remove();
})
- errorElements variable grabs all error elements. 2. If statement checks if there is something to remove, if not function stop running. 3. If there are errors to remove, the forEach will remove every error message.
@Paveldrow
Posted
it works, thanks!) yes, it was necessary to use an array and forEach)
Can you please tell me, is it possible to do such a check somehow easier and more correctly? or is this a normal solution?