When I do JQuery ".html"..this updates the div's innerHTML [closed]
开发者_如何学Go
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this questionWhat if I want to APPEND to it instead of completely replacing it?
if to append AFTER
append
appendTo
if to append BEFORE
prepend
prependTo
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.
Use the +=
string operator.
var element = document.getElementById('yourId')/
element.innerHTML += 'More content!';
This is without using jQuery.
Try the following:
$(whatever).html($(whatever).html() + string);
The above code replaces the content with a combination of the existing content and the value from the string
variable.
精彩评论