admin管理员组文章数量:1394977
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);
});
本文标签: javascriptHow to get the name of the current selected HTML tagStack Overflow
版权声明:本文标题:javascript - How to get the name of the current selected HTML tag? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744104116a2590987.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论