I need a way to determine the type of an HTML element in JavaScript. It has the ID, but the element itself could be a , a f
, a f
You can use generic code inspection via instanceof:
var e = document.getElementById('#my-element'); if (e instanceof HTMLInputElement) {} // elseif (e instanceof HTMLSelectElement) {} // elseif (e instanceof HTMLTextAreaElement) {} // elseif ( ... ) {} // any interface
Look here for a complete list of interfaces.