Detect element tag name by its class

前端 未结 5 556
情话喂你
情话喂你 2021-01-26 19:39

I would like to know if there is a way to get the name of a element by its class or id.

for exemple retur

5条回答
  •  無奈伤痛
    2021-01-26 19:51

    Try tagName :

    var input = document.getElementsByClassName("some-class")[0];
    alert(input.tagName);
    

    JSFiddle: http://jsfiddle.net/PG656/1/

提交回复
热议问题