finding the type of an element using jQuery

Jquery

Jquery Problem Overview


In jQuery, if I have a reference to an element, how can I determine what kind of element it is, for example, an input or an dropdown? Is there any way to find out?

Duplicate:

https://stackoverflow.com/questions/341900/how-can-i-determine-the-element-type-of-a-matched-element-in-jquery

Jquery Solutions


Solution 1 - Jquery

The following will return true if the element is an input:

$("#elementId").is("input") 

or you can use the following to get the name of the tag:

$("#elementId").get(0).tagName

Solution 2 - Jquery

You can use .prop() with tagName as the name of the property that you want to get:

$("#elementId").prop('tagName'); 

Solution 3 - Jquery

It is worth noting that @Marius's second answer could be used as pure Javascript solution.

document.getElementById('elementId').tagName

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionjyotishka boraView Question on Stackoverflow
Solution 1 - JqueryMariusView Answer on Stackoverflow
Solution 2 - JqueryResolutionView Answer on Stackoverflow
Solution 3 - JqueryMatas VaitkeviciusView Answer on Stackoverflow