tags:

views:

76

answers:

4

What if I want to APPEND to it instead of completely replacing it?

A: 

Use the += string operator.

var element = document.getElementById('yourId')/
element.innerHTML += 'More content!';

This is without using jQuery.

LiraNuna
A: 
$(whatever).html($(whatever).html() + string);
Martin
+2  A: 

Strangely enough there's a jQuery method called append().

<div id="x"><em>Hello</em> mum</div>
<button onclick="$('#x').append(' you slag')">Insult please</button>

Don't use x.html(x.html()+'something') or its non-jQuery counterpart innerHTML+= 'something' to add content to a document. You will be serialising the current content to HTML, then changing it, then parsing it back into objects. Apart from this being unnecessarily slow, you'll lose any non-serialisable data such as event handlers, JS references and form field values.

bobince
+7  A: 

if to append AFTER

append

appendTo

if to append BEFORE

prepend

prependTo

balexandre