Jquery: How to check if the element has certain css class/style

前端 未结 6 650
清酒与你
清酒与你 2020-12-01 02:18

I have a div:

Is there any way to check if the certa

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 02:55

    Question is asking for two different things:

    1. An element has certain class
    2. An element has certain style.

    Second question has been already answered. For the first one, I would do it this way:

    if($("#someElement").is(".test")){
        // Has class test assigned, eventually combined with other classes
    }
    else{
        // Does not have it
    }
    

提交回复
热议问题