Jquery动态创建内容

Wan*_*der 1 html javascript css jquery dom

这是我的代码的摘录

 $("#temp").append('<div class="dynamic">' );
    $("#temp").append(a[i]);
    $("#temp").append("</div>");
Run Code Online (Sandbox Code Playgroud)

这个内容在for循环中,并动态地将元素添加到具有id temp的div.

我认为它应该产生的是

<div id="temp">

.....
<div class="dynamic">
Education //value of a[i]
</div>
....


</div>
Run Code Online (Sandbox Code Playgroud)

但究竟是什么产生了它

<div id="temp">

    <div class="dynamic"></div>

    Education
Run Code Online (Sandbox Code Playgroud)

从萤火虫确认.因此,我的css样式刚刚分手.

你能看一下吗?谢谢

ade*_*neo 7

使用jQuery创建元素应该像这样:

$('<div />', {'class': 'dynamic', text: a[i]}).appendTo('#temp');
Run Code Online (Sandbox Code Playgroud)