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
  • 312,895
  • 29
  • 395
  • 388
Saad Attieh
  • 1,396
  • 3
  • 21
  • 42

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
  • 10,367
  • 2
  • 24
  • 38
-1

Element.offsetParent==null

then element is hidden

Abhijit Poojari
  • 125
  • 1
  • 7