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

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

I have a div:

Is there any way to check if the certa

6条回答
  •  星月不相逢
    2020-12-01 03:13

    CSS Styles are key-value pairs, not just "tags". By default, each element has a full set of CSS styles assigned to it, most of them is implicitly using the browser defaults and some of them is explicitly redefined in CSS stylesheets.

    To get the value assigned to a particular CSS entry of an element and compare it:

    if ($('#yourElement').css('position') == 'absolute')
    {
       // true
    }
    

    If you didn't redefine the style, you will get the browser default for that particular element.

提交回复
热议问题