jQuery if has() selector do stuff

前端 未结 5 393
逝去的感伤
逝去的感伤 2021-01-15 05:45
  • text

http://jsfiddle.net/wZ8MC/2/

jQuery(document).ready(functi         


        
5条回答
  •  时光说笑
    2021-01-15 06:12

    Check the length of your jQuery "collection":

     if (jQuery('#bad-drifting li:has(em)').length > 0) { // There is at least one element
    

    otherwise it will always be true, because what jQuery returns is always truthy.

提交回复
热议问题