javascript - Add elements without removing existing content - Stack Overflow

admin2025-04-20  0

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 mand removes my other 2 boxes, is it possible to add without to removing other boxes?

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 mand removes my other 2 boxes, is it possible to add without to removing other boxes?

Share Improve this question edited Aug 19, 2013 at 13:16 Rory McCrossan 338k41 gold badges320 silver badges351 bronze badges asked Aug 19, 2013 at 13:09 user2496077user2496077 1211 silver badge7 bronze badges 3
  • 2 append(), prepend(), insertBefore(), insertAfter(), before(), after() ..... – adeneo Commented Aug 19, 2013 at 13:11
  • possible duplicate of jquery insert new element into table cell without erasing other elements – Felix Kling Commented Aug 19, 2013 at 13:16
  • I remend to always have a look at the documentation first: api.jquery./category/manipulation. – Felix Kling Commented Aug 19, 2013 at 13:17
Add a ment  | 

2 Answers 2

Reset to default 6

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

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

http://api.jquery./append/

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745116951a285919.html

最新回复(0)