In Javascript, given the id of an element (in a String format), how can I check if the id of the element refers to a drop down list element, or a text input element?
The function should return true if the id refers to a drop down list (<select>) element, or a text input element, and false otherwise.
Try using:
document.getElementById('idNameGoesHere').tagNameSo the function could be:
You could expand this to check for
<textarea>as well.EDIT :
Or choose jbabey’s answer as it’s using
nodeNameand is better formatted.apparently
nodeNamehas wider browser support.