我要插入段落元素<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/