Posted about 8 years ago. Visible to the public.

Check whether an element is visible or hidden with Javascript

jQuery

You can say:

Copy
$(element).is(':visible')

and

Copy
$(element).is(':hidden')

jQuery considers an element to be visible if it consumes space in the document. For most purposes, this is exactly what you want.

Native DOM API

Emulate jQuery's implementation :

Copy
element.offsetWidth > 0 && element.offsetHeight > 0;

Prototype

Don't use Element#visible(), it just checks if a CSS attribute display: none exists. This is to naive for most cases.

Emulate jQuery's implementation instead:

Copy
element.offsetWidth > 0 && element.offsetHeight > 0;

Or maybe you'd even like to patch Prototype so it behaves like jQuery:

Copy
Element.addMethods({ visible: function() { return offsetWidth > 0 && offsetHeight > 0; } });

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Owner of this card:

Avatar
Henning Koch
Last edit:
about 1 year ago
by Henning Koch
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more