Inspector does not find currentTarget.className
Answered
This code:
document.querySelector(".editBackground.layer3").addEventListener("animationend", (event) =>
{
if (event.currentTarget.className.indexOf("fadeOut") !== -1)
document.querySelector(".editBackground.layer3").remove();
}, false);creates a warning since the last days. I am pretty sure it didn't before as I have this code many times in my apps and always remove all warnings
"Unresolved variable className"
Why?
Please sign in to leave a comment.
You will face similar error if you try to compile your code: TS2339: Property 'className' does not exist on type 'EventTarget'.
the reason is that the exact type of
eventis unknown, so the type is inferred as genericEvent;EventTargetinterface doesn't haveclassNameproperty. You need to explicitly tell the IDE the type of theHTMLElementwhich is your target using type annotations. See https://freshman.tech/snippets/typescript/fix-value-not-exist-eventtarget/Hi Elena,
thanks for the answer. But I do not use typescript, so I need to fix this for javascript where I have no type casting. I till struggle why this dit not happen in the past. Is there something new in IntelliJ or may I have misconfigured anything?
In JavaScript, you can use JSDoc annotations to specify types explicitly
Thanks, that works...