attr will only work if there was an attribute with that name.
You can just use
width = $('#immagineCont').get(0).clientWidth;
but you will likely need
width = $('#immagineCont').width();
which is more reliable when you want to do something that works the same in browsers (but does not include indents and borders).
You may also be interested in outerWidth .
A note on what happens and the need to get(0) : a jQuery collection (for example, $('#immagineCont') ) wraps one or more standard DOM objects that you can use with get(i) or [i] . If you want to access the native properties of a DOM object when jQuery does not offer a proxy function, you need to get this native object first.
source share