Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird IE behavior: currentStyle returns null

I am experiencing weird behavior in IE8 which appears to be an IE bug but I am not sure. When accessing currentStyle field from an element it returns null. If I view its properties in the watch window I can see that it is defined and I can view its members. It appears that if I call attributes before hand then it will return the correct currentStyle. I was wondering if anyone has seen this behavior before and knows of some workarounds. This is happening when constructing the dojo grid. I also can not override this JavaScript behavior because it is buried deep in to an external Javascript library (dojo) and I do not have access to the function in the first place to override (function is defined in another functions scope).

like image 614
Bishnu Avatar asked Nov 05 '22 08:11

Bishnu


1 Answers

The currentStyle object in IE is asynchronous. This means styles cannot be set and immediately queried. You must let IE act upon your manipulation once your JavaScript has finished making changes. You can setTimeout for 0 milliseconds, that will stick the function call on to a queue of some kind and IE will perform the DOM changes before calling the next bit of JavaScript.

like image 112
Lee Kowalkowski Avatar answered Nov 09 '22 03:11

Lee Kowalkowski