Find out if a css layer is a jquery block

I'm trying to figure out how to display a layer or not

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

So if it's true

<div class="property">

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

</div>

Then show this layer

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

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

If this is true

<div class="property">

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

</div>

Then hide this layer

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

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

It doesn't seem to work though any ideas?

thank

Jamie

+3
source share
3 answers

You are looking for a class pseudo-class :visible.

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

The above can be reduced to

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

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

You can use something like this:

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

0
source

This will work too:

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

Source: https://habr.com/ru/post/1763744/


All Articles