Skip to content

IE7/8 fails when setPosition of empty element #2326

javierarias opened this Issue Mar 9, 2012 · 4 comments

3 participants


IE7 and IE8 throws TypeError when you create an empty element (that is, no inner text, html or child nodes) and you try to set its position with setPosition() before injecting it in the DOM. However, it's OK if you inject an element with inner text = ''.

Error message is:

// throws "Unable to get value of the property 'toInt': object is null or undefined”
new Element('p').setPosition({x: 10, y: 20});
// OK
new Element('p', {text: ''}).setPosition({x: 10, y: 20});
// OK
new Element('p').inject(document.body).setPosition({x: 10, y: 20});
// OK
new Element('p').grab(new Element('span')).setPosition({x: 10, y: 20});


Even more, it doesn't fail if you set the inner text of an element to null:

// this is also OK
new Element('p', {text: null}).setPosition({x: 10, y: 20});
MooTools member
arian commented Mar 19, 2012

should probably be

    return parseInt(styleString(element, style) || 0, 10);
gonchuki commented Aug 9, 2012

I would say that the issue is a little deeper in getComputedStyle as the margin-left of the detached element with no text is returning null, and once you set some text it returns 0px.
Curious thing is that if you append this element into another one (even if it's also detached) and then you detach the element again you start getting the valid 0px value. Probably an internal IE bug where the detached element gets no layout or even no style attributes at all until you interact with it.

gonchuki commented Aug 9, 2012

edit: what was here was a dumb idea.

getting some specs and a proper pull request soon.

@arian arian closed this in aa91693 Aug 16, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.