views:

36

answers:

2

Hello !

I have some <div id="text">abc</div>. Is it possible to get it's size using JS/mooTools (width and height) when I did not set it with CSS ?

A: 

http://mootools.net/docs/core/Element/Element.Dimensions#Element:getSize

var size = myElement.getSize();
[size.x, size.y]
meder
It returns [0, 0] in this case.
hsz
Guess you need http://mootools.net/docs/more/Element/Element.Measure . The jQuery API design is far more "KISS" and easier to use imo.
meder
$("text").getSize().x seems to work fine for me even on inline elements..
vinhboy
that is because Element.Measure has FA to do with what mootools methods you'd actually use for this. `element.getCoordinates()` or `element.getSize()` work fine but will fall short on kissing you. it will work, PROVIDING that the element is--in fact--injected in the DOM and that the script block that computes it is either a `domready` callback or simply run after the element's content and dimensions are done being modified. if you have any problems, there's always www.jsfiddle.net, port the block of code you are having issues with there and post the link
Dimitar Christoff
`hello? yes. my microwave does not work. oh... have you tried jquery?`
Dimitar Christoff
A: 
$('myElement').getStyle('width'); 

returns the width of that element.

$('myElement').setStyle('width', 'value');

u can change it

thats all :)

Arwed
If element's size is set in CSS it works - otherwise it does not. In that case works only `Element.Measure`.
hsz
i thought it gets the actuall size not the size set by css ....
Arwed