-1

Is it possible to add html code inside a div block? here's my html code

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

I would like to insert new block after <div id="content-area"> with the ff code <p class='info'>Information...</p>

so it will output like.

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

Thank you!

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
ben kzo
  • 1
  • 1
  • 1
  • Did you even look at the documentation? http://api.jquery.com/category/manipulation/dom-insertion-inside/ – Felix Kling Jun 25 '13 at 19:25
  • sorry, still new to jquery. My search didn't take me to that page. – ben kzo Jun 25 '13 at 19:26
  • If you wonder how to do something in jQuery, the official documentation is the first place you should look (http://api.jquery.com/). Or the tutorials: http://learn.jquery.com/. – Felix Kling Jun 25 '13 at 19:27

3 Answers3

5
$('#content-area').prepend("<p class='info'>Information...</p>");
drull
  • 481
  • 1
  • 3
  • 9
1

use .prepend

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

$('.content-area').prepend(p);
adeneo
  • 312,895
  • 29
  • 395
  • 388