346
votes

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:

How can I determine the element type of a matched element in jQuery?

3
May be a duplicate, but it has a better answer, and the other one is tagged badly. - Rumpleteaser
@Rumpleteaser If "the other one" is tagged badly, then why don't you make use of edit button below it and tag it perfectly? - trejder

3 Answers

617
votes

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
13
votes

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

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

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

document.getElementById('elementId').tagName