jquery - how to check if element has any classes attached to it

后端 未结 8 1253
情深已故
情深已故 2021-01-27 02:20

you would imagine this would be easy to implement, but oh well..

anyway, I have an element to which classes are added or removed based of interaction on the site.

<
8条回答
  •  春和景丽
    2021-01-27 02:33

    You don't need jQuery to achive this.

    var hasNoClass = !document.getElementById("#id").className;
    
    if(hasNoClass){ /*...*/ }else{ /*...*/ }
    

    Same approach using jQuery

    var hasNoClass = !$("#id").className;
    
    if(hasNoClass){ /*...*/ }else{ /*...*/ }
    

提交回复
热议问题