rgareme
10 years agoOccasional Contributor
Problem getting css attributes
I use the following code to get the value of the css attributes. I have gotten the code from the smartbear web support.
function getStyle(element, styleProp)
{
var document = element.ownerDocument;
if (aqObject.IsSupported(document, "defaultView"))
{
// Internet Explorer 9+, Firefox, Chrome, Safari, Opera
var style = document.defaultView.getComputedStyle(element, "");
return style[styleProp];
}
else
{
// Internet Explorer 7 - 8
return element.currentStyle[styleProp];
}
}
When I use this code with IE10, the code that it executes is "return element.currentStyle[styleProp];"
For the other hand, sometimes, I get a runtime error when run this function.
function getStyle(element, styleProp)
{
var document = element.ownerDocument;
if (aqObject.IsSupported(document, "defaultView"))
{
// Internet Explorer 9+, Firefox, Chrome, Safari, Opera
var style = document.defaultView.getComputedStyle(element, "");
return style[styleProp];
}
else
{
// Internet Explorer 7 - 8
return element.currentStyle[styleProp];
}
}
When I use this code with IE10, the code that it executes is "return element.currentStyle[styleProp];"
For the other hand, sometimes, I get a runtime error when run this function.