var el = $(this.element); var f = function() { var w = 0; var cs = el.children(); if (cs.length == 0) { setTimeout(f, 100); return; } for (var i = 0; i < cs.length; i++) { w += cs.eq(i).width() + 15; } el.css({ width: w, 'height': ' auto', }); } setTimeout(f, 100);