I have a certain jQuery selection and I am looking to find the closest element (so self or parent) that is a block element (display: block
).
The style is not necessarily inline, so the selector [style*=display:block]
does not work in every case for me. I think I would need to use the computed style rather but need an efficient way to do that (if possible without a $(this).parents().andSelf().each
loop)
Asked
Active
Viewed 1,205 times
0

Horen
- 11,184
- 11
- 71
- 113
-
use CSS class: `.show {display: block;}` add class to element, in selector use `'.show'` – ryder Jan 03 '13 at 10:39
-
can you provide little HTML also! – Muhammad Talha Akbar Jan 03 '13 at 10:41
-
1`while( condition && elem.parentNode ) { elem = elem.parentNode }` and condition = http://stackoverflow.com/questions/2880957/detect-inline-block-type-of-a-dom-element – EricG Jan 03 '13 at 10:43
1 Answers
0
As @EricG has posted in the comments Detect inline/block type of a DOM element was the answer to the question:
var elementStyle = element.currentStyle || window.getComputedStyle(element, "");
var displayType = elementStyle .display;