Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find tag name in jQuery

Tags:

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 function do I need to call to get "tr"?

I need this for debugging. Thanks.

like image 326
Tom Tucker Avatar asked Feb 04 '11 21:02

Tom Tucker


People also ask

How to get tag name using jQuery and JavaScript?

get tag name using jquery and javascript 1 Get Element and ID, if any on mouseover with jQuery -1 JQuery - Find out what HTML Tag is $(this) 0 click element html, Show type html tags to text

How do I find the ID of an element in jQuery?

The #id Selector. The jQuery #id selector uses the id attribute of an HTML tag to find the specific element. An id should be unique within a page, so you should use the #id selector when you want to find a single, unique element. To find an element with a specific id, write a hash character, followed by the id of the HTML element: $("#test")

How to get the class name of an element in HTML?

Select an element that has a class name of “class”, and use the .get (0).tagName function to get this tag name. Select an element that has a class name of “class”, and use the . [0].tagName function to get this tag name. It will help you....

How to select all elements based on name in jQuery?

All selectors in jQuery start with the dollar sign and parentheses: $ (). The jQuery element selector selects elements based on the element name. You can select all <p> elements on a page like this:


Video Answer


2 Answers

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;
like image 179
ircmaxell Avatar answered Oct 18 '22 04:10

ircmaxell


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();
like image 34
Frédéric Hamidi Avatar answered Oct 18 '22 02:10

Frédéric Hamidi