I would like to know using jquery if a div is height constrained or not.
For example this div is constrained to 100px, whatever the size of the content the div will have 100px height:
<div style="height: 100px;">
bla bla
</div>
and this one is not constrained and will take the height of it's content :
<div>
bla bla
</div>
in other words I want to know if the height was set (and what if so) either by setting the style attribute or with a separate css style. Thanks
Solution for FF3.6 FF5 IE8 Chrome12 and Opera11 :
function css(a){
var sheets = document.styleSheets;
var o={};
var name;
var i=0;
while (i<sheets.length) {
var rules = sheets[i].rules || sheets[i].cssRules;
var r=0;
while(r<rules.length) {
if(typeof(rules[r].style)!="undefined" &&
!rules[r].selectorText.match(":before") && // fix for FF3.6
!rules[r].selectorText.match(":after") &&
!rules[r].selectorText.match(":link") &&
!rules[r].selectorText.match(":hover") &&
!rules[r].selectorText.match(":active") &&
!rules[r].selectorText.match(":visited") &&
!rules[r].selectorText.match(":first-letter") &&
!rules[r].selectorText.match(":-moz-focus-inner") &&
a.is(rules[r].selectorText)) {
o = $.extend(o, css2json(rules[r].style), css2json(a.attr('style')));
}
r++;
}
i++;
}
return o;
}
function css2json(css){
var s = {};
if(!css) return s;
var isMSIE = /*@cc_on!@*/0;
if (isMSIE)
{
if(typeof(css)=="object")
{
for(var i in css) {
if(i.toLowerCase)
s[i.toLowerCase()] = css[i];
}
}
else if(typeof css == "string")
{
css = css.split("; ");
for (var i in css) {
var l = css[i].split(": ");
s[l[0].toLowerCase()] = (l[1]);
};
}
}
else
{
if(css instanceof CSSStyleDeclaration)
{
for(var i in css) {
if((css[i]).toLowerCase)
s[(css[i]).toLowerCase()] = (css[css[i]]);
}
}
else if(typeof css == "string")
{
css = css.split("; ");
for (var i in css) {
var l = css[i].split(": ");
s[l[0].toLowerCase()] = (l[1]);
};
}
}
return s;
}
...
alert(css($('some selector')).height);