Skip to main content

Bug Tracker

Side navigation

#7961 closed bug (patchwelcome)

Opened January 13, 2011 08:04AM UTC

Closed January 17, 2011 01:05PM UTC

$.fn.height or $.fn.width throw a TypeError Result of expression 'elem.document.body' [null] is not an object

Reported by: miowang@hotmail.com Owned by: miowang@hotmail.com
Priority: low Milestone: 1.next
Component: manipulation Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:
Description

in line 7151:

return elem.document.compatMode === "CSS1Compat" && elem.document.documentElement[ "client" + name ] ||
  elem.document.body[ "client" + name ];

if the elem.document.documentElement[ "client" + name ] is 0, this code will try to eval "elem.document.body[ "client" + name ] " and throw a type error

Attachments (0)
Change History (3)

Changed January 13, 2011 11:51AM UTC by jitter comment:1

component: unfiledmanipulation
owner: → miowang@hotmail.com
status: newpending

Thanks for taking the time to contribute to the jQuery project by writing a bug report.

Please submit a reduced test case, which reproduces the issue you are experiencing, on http://jsfiddle.net. So that we can investigate this issue further.


How to report bugs

Changed January 13, 2011 03:32PM UTC by miowang@hotmail.com comment:2

status: pendingnew

I know I should submit a test case, but as this exception only been thrown when window's width is 0,

and in most condition, it can't show on http://jsfiddle.net/.

I found this issue is because my web app is visited by mobile device(like andorid), and sometimes the jquerymobile will try to invoke $(window).width() before the web view component is shown.

Replying to [comment:1 jitter]:

Thanks for taking the time to contribute to the jQuery project by writing a bug report. Please submit a reduced test case, which reproduces the issue you are experiencing, on http://jsfiddle.net. So that we can investigate this issue further. ----- How to report bugs

Changed January 17, 2011 01:05PM UTC by jitter comment:3

priority: undecidedlow
resolution: → patchwelcome
status: newclosed

So you are using jQuery mobile and not just jQuery core? Then maybe you should try and file this against the jQuery-Mobile bug tracker because they might have more knowledge about WebView specific bugs.

Also without more specific information or some test case which reproduces (at least sometimes) the error debugging this is difficult/impossible.

Is this error triggered by some of your code (e.g. by not using a ready wrapper or stuff like that) or by jQuery-Mobile on its own?

Overall this sounds pretty strange, normally you would call .width() only after the page has finished loading (e.g. inside the ready wrapper) and at this point clientWidth should work.

Are you sure the elem.document.documentElement[ "client" + name ] part of the conditional is failing or is already elem.document.compatMode === "CSS1Compat" evaluating to false.


With the currently available information this issue can't be fixed. If you happen to be able to create a test which reproduces this and this is indeed a bug in jQuery which can be workaround please report back and we will happily reopen this ticket.