Add html with jquery

Asked

Viewed 2,214 times

0

Good when I want to add an html to the page using jQuery I do like this:

$("body").html('ddd');

But in this way I delete old content, it is possible to add html in Body without deleting page content?

3 answers

5


What you’re looking for is append, adds inside element after all:

$("body").append('ddd');

Or prepend which adds inside the element but first of all:

$("body").prepend('ddd');

Example:

$("body").append('<p>Eu vou para depois do conteudo do body</p>');
$("body").prepend('<p>Eu vou para antes do conteudo do body</p>');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<h2>Eu vou estar no meio depois dos outros serem inseridos</h2>

  • vlw thank you so much

1

Yes, using append:

$(seletor).append();
  • 1

    vlw thank you so much

1

You can use the method append jQuery

$( "body" ).append( "Seu texto" );
  • vlw thank you so much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.