En mi código, estoy tratando de detectar si el último elemento en el que se hizo clic es un elemento de form donde sería apropiado establecer su atributo de name .
Lo que he escrito funciona:
const tag = lastElement.tagName; if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") { ... }Pero me pregunto si hay una forma más robusta/elegante de hacer esto, como
if (lastElement instanceof FormFieldElement) { ... }¿Existe una clase tan común?
Fui e investigué esto yo mismo. Según Mozilla MDN, no hay ningún elemento común después de HTMLElement
https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextAreaElement https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement
(Seleccionar también no comparte la jerarquía de clases)