Skip to content

Latest commit

 

History

History
75 lines (44 loc) · 2.57 KB

visible.md

File metadata and controls

75 lines (44 loc) · 2.57 KB
layout tags
doc-api.html
argument-list

ally.is.visible

Determines if an element is rendered.

Description

An element is considered visible if it satisfies all of the following rules:

  • Neither the element nor an element of its ancestry has display: none; applied.
  • Neither the element nor an element of its ancestry has visibility: hidden; applied, unless a closer relative in the ancestry reverts that directive by defining visibility: visible.
  • The element is not a descendant of a collapsed <details> element.
  • The element is not hosted in an <object> or <iframe> element that is considered invisible by ally.is.visible

An element can be visible, but not visible within the viewport.

Usage

var element = document.getElementById('victim');
var isVisible = ally.is.visible(element);

Arguments

Name Type Default Description
element HTMLElement required The Element to test.

The underlying rules can also be accessed in the options argument style by calling ally.is.visible.rules(options):

Name Type Default Description
context <selector> required The element to examine. The first element of a collection is used.
except <focus identification exception> {} The Element to test.

Returns

Boolean, true if the element is visible (i.e. not hidden by CSS).

Throws

TypeError if element argument is not of type HTMLElement.

Examples

Changes

  • Since v1.1.0 exceptions can be passed to ally.is.visible.rules(options).
  • Since v1.1.0 the state of the hosting <iframe> or <object> element is considered.

Notes

:::note <area> elements are not rendered by themselves, so they are always considered visible. :::

Related resources

Contributing