jquery - 在 </body> 标签 jquery 之前插入 html

标签 jquery html

我要插入段落元素<p><body> 的末尾, 就在 </body> 之前.

我试过了 insertBefore()如下所示,但它没有按预期工作。

$( "<p>Test</p>" ).insertBefore( "</body>" );

最佳答案

这意味着你想要append内容到 <body> . append() 会将内容添加到选择器元素的末尾。

Insert content, specified by the parameter, to the end of each element in the set of matched elements.

$(document.body).append("<p>Test</p>");
p {
  color: green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>

<body>
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
</body>

关于jquery - 在 </body> 标签 jquery 之前插入 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31540464/

相关文章:

javascript - jQuery id 不产生文本表示

jQuery下拉菜单闪烁

javascript - 可手动删除设置[特别是宽度和高度]

php - MySQL Workbench 5.6 在连接到本地主机时崩溃

html - 按钮未居中对齐

JavaScript:未捕获的语法错误:意外的字符串错误 jQuery

javascript - PHP - 将隐藏值传递到 jquery(第 2 部分)

javascript - TCPDF 在新标签页/窗口中打开链接

javascript - 第一次加载我的网页时图像的奇怪显示布局

html - 如何将第一个表td设置为100%宽度并使其他td低于第一个td