Reputation: 2677
Using pure JS, I need to determine the display property of an element inherited from a higher level.
The elements are inputs which are nested in a fieldset, the parent fieldset may have had it's display property set to none and if so I need to detect that condition.
I have tried getting the element.style.display property but as it is inherited this does not give me what I need ??
Any ideas ??
Upvotes: 2
Views: 1313
Reputation: 201708
By CSS rules, the display
property is not inherited (except in the sense that it can be explicitly set to the value inherit
).
If an element has display: none
, then none of its descendants are displayed, whatever their display
value might be. To detect whether an element is in such a situation, you would need to traverse the document tree upwards and check out the computed styles of all ancestors (and there’s then the complication that up to IE 8, IE does not support window.getComputedStyle
).
So it’s doable, but are you sure there isn’t a simpler way? Why would you need to know whether a field is inside an element that doesn’t get displayed (due to your settings, presumably)?
Upvotes: 1