Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JavaScript check to see if a parameter is a HTML element

Looking to see how you go about checking to see if a parameter that is passed into a function is a HTML element like <div> or <p>, etc… I’ve tried numerous things but nothing is working:

if (param !== HTMLElement) return undefined;
if (param !== Element) return undefined;
if (param !== Document) return undefined;

There has been some others but nothing seems to work – any pointers in the right direction would be great. thanks

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use the instanceof operator.

if (param instanceof HTMLElement) {
    return undefined;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading