jQuery: check if element has CSS attribute

前端 未结 6 961
故里飘歌
故里飘歌 2020-12-02 15:49

Is there a way to check an elements parents and find the first one that has a CSS background set and then return that background value?

Something like:



        
6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 16:12

    I believe the correct way to do this is to check the .length property.

    In your case you'd want to loop through all of your elements and check for the first one that meets

    .css('background').length != 0
    

提交回复
热议问题