使用javascript或jquery动态添加Div到html页面 [英] Dynamically add Div to html page using javascript or jquery
本文介绍了使用javascript或jquery动态添加Div到html页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这样的东西:
< div id =main>< / div>
< div id =created_div>< / div>
任何帮助将是美好的
解决方案
$(#parent_div)。append('< div id =created_div>< / div>');
或者如果您想要新创建的< div>
-s显示在其他人之前
$(#parent_div)。prepend('< div id = created_div >< / DIV>');
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
解决方案
$("#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>');
这篇关于使用javascript或jquery动态添加Div到html页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文