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.
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.
Share Improve this question edited Feb 4, 2018 at 11:24 Cœur 38.8k25 gold badges205 silver badges277 bronze badges asked Jul 26, 2011 at 19:35 Ax.Ax. 3203 gold badges4 silver badges12 bronze badges 2- Thanks a lot to all! There a lot of very usefull information in all your answers. – Ax. Commented Jul 26, 2011 at 19:47
- Also check: stackoverflow./questions/5347357/… – Chepech Commented Mar 9, 2012 at 22:39
6 Answers
Reset to default 7You can use the HTML DOM native tagName property. Try this:
var tag_name = this.tagName;
$('select, :checkbox, :radio').each(function(){
var tag_name = this.tagName;
alert(tag_name);
});
Just this.tagName
will give you the node name.
Try this:
$('select, :checkbox, :radio').each(function(){
alert($(this).get(0).nodeName);
});
sure... very simple
Here is a working example
http://jsfiddle/L96KG/
here is the reference source
Can jQuery provide the tag name?
You can also do:
$('select, :checkbox, :radio').each(function(el){
alert(el.tagName);
});