99Problems 99Problems - 4 months ago 12
jQuery Question

is.(':visible') == true on not-visible parent

I have:

<div style="display:none;">
<div class="checkMe"></div>
</div>


when I now check
.checkMe
if it is visible..

if($('.checkMe').is(':visible')) { ...


it is true although it is not

is there a way to achieve the check, without checking the parent-div?

Answer

It is returning the correct value.

if ($('.checkMe').is(':visible')) {
  console.log(true);
} else {
  console.log(false);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<div style="display:none;">
  <div class="checkMe"></div>
</div>