Search code examples
javascriptdomgoogle-chromemootoolsmootools-more

Mootools getComputedSize not working in Chrome


I am using the Mootools More function "getComputedSize" on a dynamically created DIV element. It works fine in Firefox but not in Google Chrome:

CSS:

.resultBox {
    width: 150px;
    height: 100px;
    position: absolute;
    z-index: 1000;
}

Javascript:

this.resultBox = new Element('div', {
    'class': 'resultBox'
});

console.log(this.resultBox.getComputedSize().width); 

The result is "150" in FF but in Chrome the result is "NaN".

Does anyone know how to fix this in Chrome without having to code the DIV into the html ?

Thanks in advance

Alex

Fixed:

this.resultBox = new Element('div', {
    'class': 'resultBox'
});

this.resultBox.inject(this.container, 'top');

console.log(this.resultBox.getComputedSize().width); 

Inject the element before trying to use this method.


Solution

  • Fixed:

    this.resultBox = new Element('div', {
        'class': 'resultBox'
    });
    
    this.resultBox.inject(this.container, 'top');
    
    console.log(this.resultBox.getComputedSize().width); 
    

    Inject the element before trying to use this method.