jQuery – How to get the tag name

To get the element tag name, you can use the tagName function. There are two ways to use it :

1) .get(0).tagName

Select an element that has a class name of “classTag1″, and use the .get(0).tagName function to display its tag name.


2) .[0].tagName

2. Select an element that has a class name of “classTag1″, and use the .[0].tagName function to display its tag name.



<title>jQuery Get Tag Name</title>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
    var $tag = $('p')[0].tagName; //'P'
    var $tag = $('.classTag1')[0].tagName; //'DIV'
    var $tag = $('#idTag1')[0].tagName; //'DIV'
    var $tag = $('p').get(0).tagName; //'P'
    var $tag = $('.classTag1').get(0).tagName; //'DIV'
    var $tag = $('#idTag1').get(0).tagName; //'DIV'
<h1>jQuery Get Tag Name</h1>
    	This is paragrah 1
	<div class="classTag1">
		This is class='classTag1'
	<div id="idTag1">
		This is id='idTag1'
Tags :

About the Author

Founder of Mkyong.com and HostingCompass.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.


  • Pingback: water ionizer plans()

  • Pingback: alkaline water brands()

  • Pingback: water ionizers()

  • Pingback: sms laan nu()

  • Pingback: parking()

  • Pingback: hurtigt laan penge nu()

  • Pingback: parking()

  • Pingback: mp4 mobile porn()

  • Pingback: DIRECTV Satellite Television()

  • Pingback: DIRECTV vs Dish()

  • Pingback: DIRECTV channels()

  • Pingback: kangen water()

  • Pingback: kangen()

  • Pingback: water purification systems()

  • Pingback: water ionizer()

  • Pingback: watch free movies online()

  • Pingback: free movie downloads()

  • Pingback: watch tv show episodes()

  • Pingback: watch free movies online()

  • Pingback: Details()

  • Pingback: Blue Coaster33()

  • kavin

    its not working for this case,please help asap


  • Jamo


  • http://www.gtholidays.in coimbatore hotels

    working for me. Thanks for sharing.

  • Pingback: List xml nodes and attribute name from xml | SeekPHP.com()

  • http://jaron.nl jaron barends

    Also, tagName is not a function, but an attribute. Upon reading “use the .get(0).tagName function”, I used automatically typed “.get(0).tagName();” in my code (with the parentheses after tagName). To avoid confusion, it would be better to change “function” in “attribute”.

  • http://umairj.com/ Umair Jabbar

    Doesn’t work !

    • joe

      fuck off

  • http://www.platinumig.com Guilherme Dupont

    You can access simply as it:


    • Dan

      that doesn’t works as good as the other solution (using jscript on the dom element directly)

    • Ymox

      With jQuery 1.7.1 and further,




      (I think it might be so from 1.6.1, see jQuery documentation dicussion about Attribute vs. Element at http://api.jquery.com/prop/#prop1). You need to use

  • Ingmar

    Hi there,

    this has nothing to do with jQuery – ‘tagName’ as a function does exist neither in jQuery nor in JavaScript. ‘tagName’ is a property of every DOM-Element – so you can use ist like ‘document.getElementById(“myId”).tagName’. The only jQuerything in your post is how you retrieve the DOM-Element: $(‘myselector’).get(0) and $(‘myselector’)[0] both just return the first DOM-Element which matches ‘myselector’ – after that, you are leaving the jQuery-Scope and are just accessing the DOM-element-property ‘tagName’

    • http://www.mkyong.com mkyong

      Hi Ingmar,

      Thanks for sharing your thoughts.