Notice Of Closure

Please note that this website is due to close down on 15th June 2020.

In the interim I will try to move as much content as possible over to my GitHub account. Thanks to everyone who has supported the site over the years.

» Help

Check if an HTML element is displayed


For element in an (X)HTML document is displayed only if its display attribute is not "none" and all of its parent elements are also visible.

The above rules need make me think "recursion" so, I developed the following routine to check if a given element in a TWebBrowser control is displayed:

function THTMLDocHelper.ElemIsVisible(const Elem: IDispatch): Boolean;
  Element: IHTMLElement;  // IHTMLElement interface to Elem
  if Supports(Elem, IHTMLElement, Element) then
    // Check if element itself is visible
    Result := ( <> 'none');
    if Result and Assigned(Element.parentElement) then
      // Element is visible: check if parent is visible (recursive)
      Result := ElemIsVisible(Element.parentElement);
    // Not an HTML element
    Result := False;

To use the function pass the IDispatch interface to the required element to it.

Author: Peter Johnson
Contributor: Peter Johnson
Added: 2008-11-26
Last updated: 2008-11-26

« Return to contents »