jardane
jardane

Reputation: 471

Dynamically add Div to html page using javascript or jquery

I want to have a main div and have the ability to dynamically add new divs at the same level as the main div. Something like this:

<div id="main"></div>
<div id="created_div"></div>

Any help would be wonderful

Upvotes: 7

Views: 18070

Answers (3)

Zoltan Toth
Zoltan Toth

Reputation: 47667

$("#parent_div").append('<div id="created_div"></div>');

or if you want the newly created <div>-s to appear before the others

$("#parent_div").prepend('<div id="created_div"></div>');

Upvotes: 8

Akhi
Akhi

Reputation: 2242

$('<div id="created_div"></div>').insertAfter('#main');

Upvotes: 4

emphaticsunshine
emphaticsunshine

Reputation: 3765

$('#main').after('<div id="created_div"></div>');

Upvotes: 6

Related Questions