jquery - 使用 jquery 在标签内插入文本 .before()

标签 jquery insert

这是我正在尝试做的一个基本示例:

<div class="container">
  <h2>Greetings</h2>
  <p>All this content, including the HTML comes from a CMS</p>
</div>

我想像这样从 CMS 插入更多内容

<div class="container">
  <h2>Greetings</h2>
  <p>NEW YORK - December 29, 2010 - All this content, including the HTML comes from a CMS</p>
</div>

此标记不起作用,因为它会将其放在

标记之前...

$('.container p').before('NEW YORK - December 29, 2010');

那么我怎样才能将它插入到标签中呢?我无法用类标记该 p 或将标记放入

标记内,因为它是从 CMS 中吐出的。

最佳答案

我找到了 prepend(),它似乎可以满足我的要求。这也是另一种解决方案。谢谢!! http://api.jquery.com/prepend/

关于jquery - 使用 jquery 在标签内插入文本 .before(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4559010/

相关文章:

mysql - Perl DBI 使用 mysql 原生多插入能力插入多行

php - 无法在 php 脚本中执行 sql INSERT 查询 (mysql_query)。 PHP/MySQL——时间敏感

mysql - 插入临时表mysql

javascript - 循环播放视频源会减慢 Chrome

jquery.append() Iframe IE 问题

javascript - Tablesorters addparse 给出 "undefined is not a function "

MySQL 将列数据从一个表复制到另一行

python - 从 python 数据帧插入 DB2 表

javascript - Jquery getJson 不调用回调

jquery - 带有下一个/上一个链接的简单循环幻灯片