jQuery - Divide width of the wrapper to the number of div`s inside

x3evolution

New Member
I need some help. I have a div wrapper and some other div's inside that will be added dynamically. The number of div's inside will be random so I need a script that will know how many div's are inside and which will be the width of the div's to fit in the wrapper perfectly.\[code\]<div id="wrapper"><div class="block">A1</div><div class="block">A2</div><div class="block">A3</div><div class="block">A4</div><div class="block">An</div></div><style>#wrapper {width:1000px;}div.block {margin:0 0 20px 20px; border:1px solid #ccc;}</style>\[/code\]If you can consider the margins and border will be great!Thank you!This is my script. It`s good, but not good handling the margins.\[code\]var ct = $('#wrapper').children().size();var dw = $('#map').width() / (ct) - 25;$("div.block").width(dw);\[/code\]Thanks to the answers below I made the script work! Thank you all!
 
Top