In my code, I am trying to detected if the last clicked on element is a form element where setting its name attribute would be appropriate.
What I've written works:
const tag = lastElement.tagName;
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") {
...
}
But I am wondering if there is a more robust/elegant way to do this, like
if (lastElement instanceof FormFieldElement) {
...
}
Is there such a common class?
I went and researched this myself. According to Mozilla MDN, there's no common element after HTMLElement
https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextAreaElement https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement
(Select also doesn't share class hierarchy)