«« Site Rescued »»

While the site is still going to move from its current host, a new site will now take its place. More Info.

The new site may have less content, but the core will now remain. And it will now play nicely with phones! Keep an eye on the DelphiDabbler Blog for news.

» 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 := (Element.style.display <> '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 »