2013-06-25 39 views
-1

是否可以在div块中添加html代码? 这里是我的html代码jQuery - 在DIV块中添加html代码

<div id="content-area"> 
<p>welcome to ...</p> 
</div> 

我愿与FF代码<p class='info'>Information...</p>

所以它会输出等之后<div id="content-area"> 插入新的块。

<div id="content-area"> 
<p class='info'>Information...</p> 
    <p>welcome to ...</p> 
    </div> 

谢谢!

+0

你连看的文件? http://api.jquery.com/category/manipulation/dom-insertion-inside/ –

+0

对不起,仍然是新的jquery。我的搜索没有把我带到那个页面。 –

+0

如果你想知道如何在jQuery中做些什么,官方文档是你应该看的第一个地方(http://api.jquery.com/)。或者教程:http://learn.jquery.com/。 –

回答

5
$('#content-area').prepend("<p class='info'>Information...</p>"); 
+0

非常感谢你drull。 –

+0

ben kzo,您好。 – drull

1

使用.prepend

$('#content-area').prepend($('<p>', { 'className' : 'info',text : 'your text'})); 
1
var p = $('<p />', {'class':'info', text: 'Information...'}); 

$('.content-area').prepend(p);