You've got the right idea, but don't worry about the css width
property. Its better to use the .width() method built into jQuery to
get what you want. You could do something like this:

var size = 0;
$("#container > .content").each(function(){
  size += $(this).width();
});

I have not tested the code but something like this should work just
fine.

Brian

On Sep 10, 5:31 am, Shoaib <[EMAIL PROTECTED]> wrote:
> I have a div (#container) possess a number of contents in children
> divs (.content). '.content' is styled as: {display:inline;
> float:left;}
> How can I get the collective width of all those '.content'
>
> I tried the followng
> var contents = $("#container > .content");//It is fine and returns
> array of divs
> var size = 0;
> var i = 0;
> for(i=0;i<contents.length;i++){
>      size +=contents[i].css("width");
>      //OR other way
>      size += contents[i].style.width;
>
> }
>
> but no result
>
> however $("#container > .content").css("width") returns the width of
> first child div only.
>
> Is there is any way to traverse all the children divs for their
> widths?
>
> Shoaib Nawaz

Reply via email to