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?
The typeof operator when applied to the jQuery object returns the string "function" . Basically that does mean that jQuery is a function.
$() = 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.
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.
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
You can use .prop() with tagName
as the name of the property that you want to get:
$("#elementId").prop('tagName');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With