I am not that experienced with javascript and I am having a problem reading some properties using javascript.
I have a menu bar sitting inside a div that is centred. Some menu options drop down from the bar, with their left position being set in css.
I want to read the left position using JS becaues the position of the dropdown boxes will change depending on the width of the browser plus every time I change a menu I hqve to recode the values that turn the menus on and off.
I found the code below, but in Firefox it returns 0px (seems to be wrong) while IE returns 160px (correct, but does not allow for the centering - just reporting the left within its div).
Expand|Select|Wrap|Line Numbers
- var x = document.getElementById(el);
- if (x.currentStyle)
- {
- var y = x.currentStyle[styleProp];
- }else if (window.getComputedStyle){
- var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
- }
- return y;
- }
Thanks in advance,
Dave