im no expert javascript coder. i used like 5 hours now trying alot of different stuff. and i noticed some things that i cant figure out im trying to get this to work
width = $('#immagineCont').attr('clientWidth');
but it returns undefined i tried doing
width = $('#immagineCont').attr('id');
witch returned #immagineCont i guess is correct.
when i use
$('#immagineCont')
i get this in firebug 1) 2)
so what im trying to do is get the damn clientWidth witch seems impossible. i even tryed children("0") and children("#0") im going blow my brains soon ^^
im no expert javascript coder. i used like 5 hours now trying alot of different stuff. and i noticed some things that i cant figure out im trying to get this to work
width = $('#immagineCont').attr('clientWidth');
but it returns undefined i tried doing
width = $('#immagineCont').attr('id');
witch returned #immagineCont i guess is correct.
when i use
$('#immagineCont')
i get this in firebug 1) http://bildr.no/view/1325119 2) http://bildr.no/view/1325120
so what im trying to do is get the damn clientWidth witch seems impossible. i even tryed children("0") and children("#0") im going blow my brains soon ^^
Share Improve this question asked Nov 23, 2012 at 12:12 coldasicecoldasice 691 silver badge6 bronze badges2 Answers
Reset to default 6attr
would only work if there was an attribute with this name.
You may simply use
width = $('#immagineCont').get(0).clientWidth;
but you more probably need
width = $('#immagineCont').width();
which is more reliable when you want to do something that works the same across browsers (but doesn't include padding and borders).
You might also be interested by outerWidth.
A note about what happens and the need for get(0)
: a jQuery collection (like $('#immagineCont')
) wraps one or more standard DOM objects that you can get using get(i)
or [i]
. If you want to access native properties of the DOM object, when jQuery doesn't offer a proxy function, you need to get this native object first.
Use jQuery width()
for this purpose:
var width = $('#immagineCont').width();
Also there is no attribute set to the element called clientWidth. This is a javascript property so it can be retrieved by dereferencing the jQuery object:
var width = $('#immagineCont')[0].clientWidth;