How to find tag name in jQuery
Is there a jQuery function that tells you the tag name of a given element?
Say I have an element that represents a <tr>
. What f开发者_StackOverflow中文版unction do I need to call to get "tr"
?
I need this for debugging. Thanks.
It should be quite easy, just use the .get()
method:
nativeElement.tagName;
or
jQueryElement.get(0).tagName;
Or for all cases:
$(element).get(0).tagName;
If you have a <tr>
element, do:
var tagName = tr.tagName.toLowerCase();
If your <tr>
element is wrapped in a jQuery object, do:
var tagName = tr.get(0).tagName.toLowerCase();
try this for tag name
$('tr')[0].nodeName
This simple JavaScript code will get you the tag name of any given element:
document.getElementById("<element ID>").tagName
or
//inside a method
this.tagName
精彩评论