简体   繁体   English

jQuery:如何在HTML文件的末尾添加div?

[英]jQuery: how do I add a div to the end of my HTML file?

I saw in the documentation that .append allows you to add things to an element. 我在文档中看到.append允许您向元素添加内容。 But I want to end a div right before the </body> tag 但我想在</body>标记之前结束div

You can use this: 你可以用这个:

$('body').append('<div>footer</div>');

but also this: 而且这个:

$('<div>footer</div>').appendTo('body');

or this: 或这个:

$('body').html($('body').html()+'<div>footer</div>');

Reference with differences here: http://api.jquery.com/appendTo/ 参考差异在这里: http//api.jquery.com/appendTo/

$('body').append('<div />');

等等,为什么这不起作用?

$("body").append('<div id="your_div" />');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM