简体   繁体   English

jQuery HTML插入最后

[英]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: 嗨,我必须使用Jquery html()在html中添加代码,问题是我需要将其添加到最后一个element.My当前的HTML如下所示:

<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: 我的jQuery代码将如下所示:

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. 当我使用html() ,虽然ID正确附加,但ID为review_lister_header div仍然丢失。 How can i overcome this issue? 我该如何克服这个问题?

您可以使用append

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

html() method replaces all the inner html of element. html()方法替换了元素的所有内部html。 USe append() to insert at end of element 使用append()插入元素的末尾

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

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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