[Vuejs]-Vue 3 Composition API – TypeError: Cannot read properties of null (reading 'style')

0👍

ClassList.contains returns a boolean value.

you can see more documentation here

i think what you might be trying to do is

title.value.style.backgroundColor = "red";

0👍

I did not use TS for reproduction of the problem, but I found two mistakes in your code.

The first one is that you use dot "." inside contains(".title") and it’s not needed.

The second one is that you are trying to add some styles not to DOM element, but Boolean, that is returned after contains(".title") part of your code.

My solution is here

if(title.value.classList.contains("title")) title.value.style.backgroundColor = 'red';

Leave a comment