通过类检测元素标签名称 [英] Detect element tag name by its class
本文介绍了通过类检测元素标签名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有方法通过它的类或id获取元素的名称。
I would like to know if there is a way to get the name of a element by its class or id.
例如< ; input class =some-classtype =text/>
返回input
b $ b
推荐答案
尝试 tagName
: $ b
Try tagName
:
var input = document.getElementsByClassName("some-class")[0];
alert(input.tagName);
JSFiddle: http://jsfiddle.net/PG656/1/
JSFiddle: http://jsfiddle.net/PG656/1/
这篇关于通过类检测元素标签名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文