开发者

find out if css of layer is block jquery

开发者 https://www.devze.com 2023-01-15 11:19 出处:网络
I\'m trying to figure a way of finding out if a layer is displayed or not if ($(\'.property > .evenprop\').css(\'display\',\'block\')){

I'm trying to figure a way of finding out if a layer is displayed or not

if ($('.property > .evenprop').css('display','block')){
    $('.otherprop').show();
    }
    else {
    $('.otherprop').hide();
    }

So something like if this is true

<div class="property">

<div class="evenprop" style="display:block">blah</div>

</div>

Then show this layer

<div class="otherprop">blahblah</div>

$('.otherprop').show();

Else if this is true

<div class="property">

<div class="evenprop" style="display:none">blah<开发者_Python百科/div>

</div>

Then hide this layer

<div class="otherprop">blahblah</div>

$('.otherprop').hide();

Can't seem to get this to work though any ideas?

Thanks

Jamie


You're looking for the :visible pseudo-class.

if ($('.property > .evenprop').is(':visible')){
    $('.otherprop').show();
} else {
    $('.otherprop').hide();
}

The above can be reduced to

$('.otherprop').toggle($('.property > .evenprop').is(':visible'));


$('.property > .evenprop').css('display','block') will set the CSS. If you need to check use :visible selector

You can use something like this:

if($('.property > .evenprop :visible').size!=0)


This would work too:

if ($('.property > .evenprop').css('display') == 'block'){ 
    //...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号