jQuery if Element has an ID?

前端 未结 11 2037
北恋
北恋 2020-12-25 10:01

How would I select elements that have any ID? For example:

if ($(\".parent a\").hasId()) {
    /* then do something here */
}

I, by no mean

11条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-25 10:56

    I seemed to have been able to solve it with:

    if( $('your-selector-here').attr('id') === undefined){
        console.log( 'has no ID' )
    }
    

提交回复
热议问题