JQuery detect if a tag is self closing

后端 未结 4 1756
深忆病人
深忆病人 2021-01-17 20:30

Is there a way to detect if a tag is self closing with JQuery like an image tag? Something dynamic not just an image tag.

if ($(\'.selector\')[0].tagName.to         


        
4条回答
  •  一生所求
    2021-01-17 20:45

    jQuery uses this list internally:

    /^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i
    

    You can do the same:

    if(/^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i.test($('.selector')[0].tagName)) {
    //do something
    }
    

提交回复
热议问题