jQuery (Append)

爷,独闯天下 提交于 2019-12-13 04:14:35

问题


For instance I have this html code

<div class="messageContainer">
  <div class="message">
  </div>
</div>

---Here

<div class="messageContainer">
  <div class="message">
  </div>
      <here> :)
</div>

Now I need to create a div with some information located in the text ("---Here"). Is there any way how obviously by using jQuery.


回答1:


You're looking for the after() command:

$("#messageContainer").after("<div>");

Though in your example, this will add it after every messageContainer. You will need to adjust the selector appropriately. So you'd want #messageContainer:first to add it after only the first container, for example.

before() is also available.



来源:https://stackoverflow.com/questions/1955152/jquery-append

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!