开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜