Skip to main content

Bug Tracker

Side navigation

#7976 closed bug (duplicate)

Opened January 14, 2011 09:06PM UTC

Closed January 14, 2011 10:07PM UTC

Last modified January 14, 2011 10:07PM UTC

calling position() on dom elements in memory throws TypeError

Reported by: harman.elaine@gmail.com Owned by:
Priority: low Milestone: 1.next
Component: offset Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:
Description

http://jsfiddle.net/p667T/1/

OS tested: win7, OS 10.5

Browsers tested: FF 3.6.13, IE7 & 8; broken on all.

Broken in jQuery 1.4.4 and 1.4.3; 1.4.2 seems to work as expected.

Description:

Calling .position() on dom elements that only exist in memory, i.e. that haven't been rendered yet, throws an exception. In <= 1.4.2, it returned a map with top,left = 0, which seems preferable.

Repro:

(See jsfiddle case)

1. Execute the following at any time:

var position = $("<div/>").position()

Expected:

"position" variable is assigned a map with top/left properties set to 0

Actual:

Exception is thrown:

name: TypeError

message: setting a property that has only a getter

stack:

()@http: //code.jquery.com/jquery-1.4.4.min.js:164
((function (j, s) {return new (b.fn.init)(j, s);}))@http: // fiddle.jshell.net/p667T/1/show/:22
((function () {try {var position = $("<div/>").position();console.log(position);} catch (err)
{console.log(err);}}))@http: //code.jquery.com/jquery-1.4.4.min.js:26
([object Object])@http ://fiddle.jshell.net/p667T/1/show/:18
([object Object])@http ://code.jquery.com/jquery-1.4.4.min.js:63
([object Event])@http ://code.jquery.com/jquery-1.4.4.min.js:57
Attachments (0)
Change History (3)

Changed January 14, 2011 09:56PM UTC by rwaldron comment:1

component: unfiledoffset
priority: undecidedlow
status: newopen

Confirmed.

"offset.top -= parseFloat( jQuery.css(elem, "marginTop") ) || 0; "

Changed January 14, 2011 10:07PM UTC by rwaldron comment:2

resolution: → duplicate
status: openclosed

Changed January 14, 2011 10:07PM UTC by rwaldron comment:3

Duplicate of #7602.