Probably a dumb question, but is there a way in JavaScript to find out a form element’s type (text, checkbox, etc.) from a form element after finding it by name or id? Either in plain old JavaScript or using jQuery-style syntax or methods would be ideal.
Example:
<input type="text" name="my_text_input" id="my_text_input"/>
<script>var element = document.getElementById('my_text_input'); // now how to get the element type?</script>
I’m not looking for alternatives, this is exactly what I want to do. I’m making a sort of screen scraper that needs to collect this information.
The
typeproperty will give you this…However, you have also tagged the question with jQuery, so you could use…
jsFiddle.