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.
You 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);
});
仅this.tagName
会给您节点名称。
Try this:
$('select, :checkbox, :radio').each(function(){
alert($(this).get(0).nodeName);
});
sure... very simple
Here is a working example
here is the reference source
You can also do:
$('select, :checkbox, :radio').each(function(el){
alert(el.tagName);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.