S
S
sneeeg2020-12-18 19:32:07
typescript
sneeeg, 2020-12-18 19:32:07

What is causing the classList error?

const mail = document.querySelector('input[name="mail"]') as HTMLInputElement

mail.onblur = function() {
        if (!mail.value.includes('@')) {
            mail.classList.add('invalid');
            mail_error.textContent = 'Пожалуйста, введите правильный email.'
        }
    };

    mail.onfocus = function() {
        if (this.classList.contains('invalid')) {
            this.classList.remove('invalid');
            mail_error.textContent = "";
        }
    }

TS2339: Property 'classList' does not exist on type 'GlobalEventHandlers'.
this.classList.contains('invalid')
this.classList.remove('invalid')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2020-12-19
@sneeeg

Use addEventListener.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question