Does jQuery have any function to determine the tag type of the DOM element(s) referenced by jQuery object? I am writing a jQuery plugin and...
jQuery.fn.myPlugin() {
return this.each(function() {
var $this = $(this);
// <---------------------------------------HERE!
});
}
I would like to know if this
is an <input>
element or a <div>
element, without directly using the DOM.
Do this:
this.nodeName;
...or to be safe, convert it to a specific case:
this.nodeName.toLowerCase();
The nodeName
property is a property that is widely supported and will give you the tag name in the case of an element node (as in your case).
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