JQuery (': visible') acts funny.

I am having a strange problem with checking the visibility of an object using jQuery.

I have this JS test:

alert($myObject.css('display'));
alert($myObject.is(':visible'));

The first warning displays a “block”, which makes sense, since firebug clearly shows that it is set to display: block and you can see the object on the page in the browser.

The second warning, however, displays "false". Which doesn't make any sense to me.

I misunderstand what it is (': visible')?

+5
source share
4 answers

Consider this HTML:

<div id="div1" style="display: none;">
    <div id="div2">
        <p>Some div content</p>
    </div>
</div>

and this javascript:

$myObject = jQuery('#div2');
alert($myObject.css('display')); // 'block'
alert($myObject.is(':visible')); // false

There are several reasons why it $myObjectmay not be displayed, even if it has a style display: none. For more details see : overview documents .

?

+9

:visible display css.

false, :

  • CSS .
  • = "".
  • 0.
  • , .
+4

: :

:

  • CSS .
  • = "".
  • 0.
  • , .

, .

+3

, :

- CLICK , , , .;)

Alas, what happened here. Another click event was attached to this object, which was set to hide the parent. This was the first shot - before my logic checked to see if it was visible.

At the end: user error.

In the event of a user error, there must be some form of reputation .;)

+1
source

All Articles