Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
How to detect if an element is a form element

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!