Adding html with jquery

0

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

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

But in this way I delete the old content, can I add the html in the Body without deleting the content of the page?

    
asked by anonymous 16.12.2016 / 20:02

3 answers

5

What you're looking for is append , add within the element after all:

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

Or prepend that 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>
    
16.12.2016 / 20:07
1

Yes, using append :

$(seletor).append();
    
16.12.2016 / 20:07
1

You can use jQuery's append method

$( "body" ).append( "Seu texto" );
    
16.12.2016 / 20:08