简体   繁体   中英

Jquery html insert on last

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?

您可以使用append

$('#user_reviews_list').append(userReviewHtml);

html() method replaces all the inner html of element. USe append() to insert at end of element

API refrence: http://api.jquery.com/append/

您应该使用append将新元素添加到结尾:

$('#user_reviews_list').append(/*your new element*/);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM