Detect element tag name by its class

前端 未结 5 515
情话喂你
情话喂你 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

    Actually $('.some-class') returns an array of elements with this class, so you have to loop through it:

    $('.some-class').each(function(){ 
        console.log(this.nodeName); 
    });
    

    this will output their node names to console

提交回复
热议问题