Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery: check if element is in normal flow

What is the most elegant way to check whether an element is in the normal flow using jQuery?

According to the CSS3 specification,

A box belongs to the flow if:

The used value of its ‘display’ is ‘block’, ‘list-item’, ‘table’ or template.

The used value of its ‘float’ is ‘none’.

The used value of its ‘position’ is ‘static’ or ‘relative’.

It is either a child of the flow root or a child of a box that belong to the flow.

Should I just check for all these conditions, or is there a better way?

like image 405
sbichenko Avatar asked Dec 11 '12 19:12

sbichenko


1 Answers

I doubt theres a better way, but a different way would be:

1) Surround the element with a wrapper

2) Compare height and width of wrapper with wrapped element

For example:

$('#elementToTest').clone().addClass('clone').wrap('<div></div>')
if($('#elementToTest.clone').height()>$('#elementToTest.clone').parent().height()){
    //outside the normal flow
}
like image 119
Aakil Fernandes Avatar answered Sep 21 '22 02:09

Aakil Fernandes