I'm hoping to use jQuery to get the total widths of all the DIVs in a container and set that width to the body.
I presume I need something to the effect of
$('#container > div').width().[mulitply by quantity of DIVs in container].[set this result to body width]
Unfortunately just typing strings of what I want isn't good enough! Can someone point me in the right direction?
开发者_StackOverflow社区Any help appreciated!
This could look like:
var overall_width = 0;
$('#container > div').each(function(index, elem) {
var $elem = $(elem);
overall_width += $elem.outerWidth() + parseInt($elem.css('margin-left'), 10) + parseInt($elem.css('margin-right'), 10);
});
$(document.body).width(overall_width);
This would add all the children div node
's width along with the margin (if there is any) and finally set the width from document.body
.
精彩评论