jQuery(附加) [英] jQuery (Append)

查看:93
本文介绍了jQuery(附加)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有这个html代码

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>

现在,我需要创建一个带有一些位于文本中的信息的div("--- Here"). 有没有办法通过使用jQuery如此明显.

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

推荐答案

您正在寻找after()命令:

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

尽管在您的示例中,它将在每个messageContainer之后添加它.您将需要适当地调整选择器.因此,例如,您希望#messageContainer:first仅将其添加到第一个容器之后.

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()也可用.

这篇关于jQuery(附加)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆