通过类检测元素标签名称
问题描述:
我想知道是否有方法通过它的类或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/