Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Argument 1 of Window.getComputedStyle is not an object #61

Closed
multiformeingegno opened this issue Aug 30, 2014 · 8 comments
Closed

Comments

@multiformeingegno
Copy link

Here's what I get:
bigtext

jQuery 2.1.1

@erfanimani
Copy link

Hmm interesting, I'm getting that as well, but only in IE and Firefox (not in Chrome).

The problem lies in this part:

          var test = $('<div/>').css({
              position: 'absolute',
              'font-size': '14.1px'
            }).appendTo(document.body).get(0),
            computedStyle = window.getComputedStyle( test, null );

It seems test always returns undefined, but Chrome doesn't throw an exception, whereas Firefox and IE do.

I think the issue is that @multiformeingegno and I are including the script in the head of our html, instead of before the body end tag. In our case body doesn't exist yet, and appendTo(document.body) returns undefined!

Let me just try to confirm this..

@erfanimani
Copy link

Ok yeah, that was the problem - moving the script to before the body end tag worked. Not sure if you'd classify that as a bug or not! :)

@ghost
Copy link

ghost commented Feb 2, 2015

I can confirm this. The plugin is unusable on Firefox/Yosemite.

Here's the fix:

          var computedStyle="";
          try{
          var test = $('<div/>').css({
              position: 'absolute',
              'font-size': '14.1px'
            }).appendTo(document.body).get(0),
            computedStyle = window.getComputedStyle( test, null );
          }catch(e){
            //do nothing
          }
          return computedStyle ? computedStyle.getPropertyValue( 'font-size' ) === '14px' : true;

@zachleat
Copy link
Owner

zachleat commented Feb 4, 2015

The plugin needs to run either on DOMContentLoaded or onload. I’ll probably build this into the plugin eventually so that it handles it transparently.

@fezzik1620
Copy link

I can confirm seeing this on Chrome beta 41.0.2272.74. An associate of mine on the same network, loading the same internal page not using the beta release of Chrome is not seeing this behavior.

@ashinzekene
Copy link

Window.getComputedStyle does not work when you use document.querySelector. it works when u use getElementById

@muskanbardia1
Copy link

how to resolve this error in react?

@muskanbardia1
Copy link

Window.getComputedStyle: Argument 1 is not an object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants