Dynamically add Div to html page using javascript or jquery

前端 未结 3 1683
粉色の甜心
粉色の甜心 2021-02-09 06:44

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:

相关标签:
3条回答
  • 2021-02-09 06:46
    $('<div id="created_div"></div>').insertAfter('#main');
    
    0 讨论(0)
  • 2021-02-09 06:55
    $('#main').after('<div id="created_div"></div>');
    
    0 讨论(0)
  • 2021-02-09 06:58
    $("#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>');
    
    0 讨论(0)
提交回复
热议问题