Detect element tag name by its class

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

    use this:

    $('.classTag').get(0).tagName;
    

    or this:

    $('.classTag')[0].tagName;
    

    for ex we have this markup:

    my div
    var $tag = $('.classTag')[0].tagName; //this will return 'DIV'as result alert($tag);

提交回复
热议问题