jQuery if Element has an ID?

前端 未结 11 2054
北恋
北恋 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:42

    You can using the following code:

       if($(".parent a").attr('id')){
    
          //do something
       }
    
    
       $(".parent a").each(function(i,e){
           if($(e).attr('id')){
              //do something and check
              //if you want to break the each
              //return false;
           }
       });
    

    The same question is you can find here: how to check if div has id or not?

提交回复
热议问题