How to prevent TypeError: e.target.getAttribute is not a function? [closed]

Tags: , ,



What I’m trying to do is the inner code (result) will only work when there’s an attribute of Validity.
But since my target doesn’t have an attribute of Validity, I want to prevent the inner code to run by having an if checking.

What can I do to check/prevent the error of TypeError: e.target.getAttribute is not a function?

enter image description here

Answer

use optional chaining or hasOwnProperty() method



Source: stackoverflow