0

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?

99Problems
  • 155
  • 1
  • 2
  • 8
  • 2
    As you can see from the answer below, what you have should (and does) work absolutely fine. Are you sure you only have one `.checkMe` element in the DOM? – Rory McCrossan Aug 04 '16 at 13:47
  • Returns `false` Check [fiddle](https://jsfiddle.net/uo463ave/) – Alex Char Aug 04 '16 at 13:48
  • `console.log($('.checkMe').is(':visible'));` prints `false`, as I would expect. What is the body of your `if` block (and the rest of your code) and what are you seeing that indicates it is evaluating to `true`? – ryachza Aug 04 '16 at 13:49

2 Answers2

2

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>
Nick
  • 3,231
  • 2
  • 28
  • 50
1

I am not sure about this answer

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


var element = jQuery('.checkMe').clone();
element.appendTo('#samp');
if($('.checkMe').is(':visible'))
{
    alert('visible');
}
else
{
    alert('not visible');

}
ubm
  • 636
  • 11
  • 21