Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

finding the type of an element using jQuery

Tags:

jquery

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?

like image 509
jyotishka bora Avatar asked Mar 03 '09 22:03

jyotishka bora


People also ask

What is Typeof in jQuery?

The typeof operator when applied to the jQuery object returns the string "function" . Basically that does mean that jQuery is a function.

What is $() in jQuery?

$() = window. jQuery() $()/jQuery() is a selector function that selects DOM elements. Most of the time you will need to start with $() function. It is advisable to use jQuery after DOM is loaded fully.

What is find method in jQuery?

jQuery find() Method The find() method returns descendant elements of the selected element. A descendant is a child, grandchild, great-grandchild, and so on. The DOM tree: This method traverse downwards along descendants of DOM elements, all the way down to the last descendant.


2 Answers

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 
like image 71
Marius Avatar answered Oct 06 '22 17:10

Marius


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

$("#elementId").prop('tagName');  
like image 28
Resolution Avatar answered Oct 06 '22 17:10

Resolution