detect div height using javascript or jquery

August 26, 2011 at 18:28:00
Specs: Windows 7
Hi I need to detect the div height that appears to visitors and then change a css class with the div height
Any help will be appreciated
Thank you

See More: detect div height using javascript or jquery

Report •

August 28, 2011 at 20:00:39
I typically use the object's style properties as they seem to work cross-browser without a lot of fuss.

or maybe
document.getElementsByTagName("DIV")[div tags index position or its 'ID name'].style.height

The downside is the property may or may not be set, so you'll have to check the returned value before using it.

Not quite sure about the second part; if you mean dynamic css rule changes, I think you can access style sheets using something like

document.styleSheets[index].cssRules // standard
document.styleSheets[index].rules  // IE

for(i=0; i < document.styleSheets[0].cssRules.length; ++i) {

if the selectorText contains the class you're after, you can alter it with something like

document.styleSheets[0].cssRules[index position matching selectorText].cssText = "height: " + div_height_var + "px";


Report •
Related Solutions

Ask Question