How to dynamically create div using jQuery?

Hi,

can you tell me how to dynamically create divs using jQuery. For example, how to make three divs inside body, so every next div will be removed from left 20px?

That’s pretty basic jQuery stuff, it’s explained pretty well in the jQuery docs.
But here ya go:


$(function() {
    for(i=0; i<3; i++) {
         $('<div>').css({marginLeft: 20}).appendTo('body');
    }
});

First i created element with width 100% one below another with jQuery using for loop. Then in another for loop a created small boxes horizontally. But that only appended in first div not in every else.

http://img192.imageshack.us/img192/3599/boxesn.png

Do you know what I mean? How it is possible to do that?

$(‘#button’).click(function() {
for(int i=0;i<=3;i++){
$(‘body’).append(‘<div id=“someid”>content</div>’);
}
});