Search code examples
javascriptjquerytagname

How to get the name of the current selected HTML tag?


I have selected some tag with jQuery:

$('select, :checkbox, :radio').each(function(){
   // ...
});

Now, I need to get the name of the current tag:

$('select, :checkbox, :radio').each(function(){
   var tag_name = $(this). ???
   alert(tag_name);
});

Expected result: "select", "input" and so on.

So, I need to know, how to get the tag name of element. Maybe without jQuery, with native javascript functions - no matter how.


Solution

  • You can use the HTML DOM native tagName property. Try this:

    var tag_name = this.tagName;