0

In pure javascript/DOM is there a way to know if an element is hidden? As in I have something like this:

    <div id="creator" hiddden="hidden">
      <dl>
        <dt> <label for="creator">Creator:</label> </dt>
        <dd>
           <input type="text" name="creator"/>
        </dd>
      </dl>
    </div>

So from acquiring the form element only, is it possible to find if its hidden because an ancestor has a hidden attribute?

Many thanks

adeneo
  • 303,455
  • 27
  • 380
  • 377
Saad Attieh
  • 1,286
  • 2
  • 20
  • 41

2 Answers2

1

Look how jQuery does it:

jQuery.expr.filters.hidden = function( elem ) {
    // Support: Opera <= 12.12
    // Opera reports offsetWidths and offsetHeights less than zero on some elements
    return elem.offsetWidth <= 0 && elem.offsetHeight <= 0;
};

Demo: http://jsfiddle.net/xJ2Dr/

gog
  • 5,680
  • 1
  • 18
  • 31
-1

Element.offsetParent==null

then element is hidden