Reputation: 371
Hi i have to add a code in html using Jquery html(), the problems is i need to add it on last element.My current Html will look as follow:
<div class="column column-sub-alpha " id="user_reviews_list">
<div id="review_lister_header">
<h3 id="recentReviews">Recent Reviews</h3>
<p class="formNote">
<a href="#">2 Reviews</a>
</p>
</div>
<!-- need to add here from Jquery -->
</div>
my jquery code will look as follow:
var userReviewHtml = '<p>Hello</p>';
$('#user_reviews_list').html(userReviewHtml);
When i use html()
my div with id review_lister_header
is missing although it append correctly. How can i overcome this issue?
Upvotes: 0
Views: 107
Reputation: 48640
You should use append to add a new element to end:
$('#user_reviews_list').append(/*your new element*/);
Upvotes: 0
Reputation: 171669
html()
method replaces all the inner html of element. USe append()
to insert at end of element
API refrence: http://api.jquery.com/append/
Upvotes: 0
Reputation: 94101
You can use append
:
$('#user_reviews_list').append(userReviewHtml);
Upvotes: 4