Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does jQuery have any function to determine the tag type of the DOM element(s) referenced by jQuery object?

Tags:

jquery

dom

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.

like image 534
pyon Avatar asked Feb 25 '11 03:02

pyon


1 Answers

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).

like image 159
user113716 Avatar answered Sep 17 '22 22:09

user113716