2013-06-25 40 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);