user2496077
user2496077

Reputation: 121

Add elements without removing existing content

I use jQuery .html() but is it possible to add an element without to removing the other HTML elements?

My code look so:

<div id="contentboxes">
    <div class="con1">content 1</div>
    <div class="con1">content 2</div>
</div>

I have tried this with jquery:

$('#contentboxes').html('<div class="con3">Content 3</div>');

But this command removes my other 2 boxes, is it possible to add without to removing other boxes?

Upvotes: 1

Views: 2797

Answers (2)

Spokey
Spokey

Reputation: 10994

$('#contentboxes').append('<div class="con3">Content 3</div>');

http://api.jquery.com/append/

Upvotes: 2

Strille
Strille

Reputation: 5781

use .append() instead of .html().

Upvotes: 6

Related Questions