Forum Moderators: not2easy
I have various html tags/elements such as:
<select name="test" class="selectStyle" id="test">
<input type="text" name="test2" id="test2" class="textStyle">
I am after these style width's using something like document.getElementById("test").style.width but nothing is displayed! Am I doing this wrong or is it not possible?
TIA,
-Gs
function getStyle(el,styleProp)
{
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;
}
1. Try using single quotes insead of double quotes.
2. Try explicitly setting a width property for those elements, even if it's value starts at "auto." I've had instances where javaScript was unable to alter a style property that didn't already have a value set in the CSS.
If neither of those help, I suggest posting to the JavaScript Forum [webmasterworld.com]. The experts there will certainly be able to get you straight.
cEM