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
2009-10-08 23:04:02
+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
2009-10-08 23:04:43