Forum Discussion

rgareme's avatar
rgareme
Occasional Contributor
10 years ago

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. 




2 Replies

  • rgratis's avatar
    rgratis
    Frequent Contributor
    I'd add in some debugging log statements to check whether element and document are both objects that are not null.  It could be that the objects aren't being returned properly from IE10.
  • ishan_07's avatar
    ishan_07
    Occasional Contributor

    Hello,
    You should try selector.html() to get the value of particular element or attribute.