Positioning Elements (divs) Dynamically

Positioning Elements (divs) Dynamically

Is there a way to position divs dynamically using jQuery? I want to achieve this basic layout but rather than typing in each div's absolute position I'm wondering whether jQuery can somehow specify an offset/position (so that each div is a specified distance from the previous div) together with the number of divs per row to achieve the same thing.

JSFiddle

I realise I could set the divs as in-line blocks in the parent div but I have reasons for not wanting to do that. I would like if it is possible for the number of div's per row to either adjust automatically based on the width of the parent div or to be able to specify the number of div's per row numerically.

Is this is possible to achieve?