cancel
Showing results for 
Search instead for 
Did you mean: 

Problem getting css attributes

Highlighted
Occasional 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. 




2 REPLIES 2
Highlighted
Frequent Contributor

RE: Problem getting css attributes

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.
Highlighted
Occasional Contributor

Re: Problem getting css attributes

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

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors