使用jQuery将div附加到文档末尾吗? [英] Append div to end of document with jQuery?

查看:66
本文介绍了使用jQuery将div附加到文档末尾吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用jQuery编写一个将div附加到网页末尾的函数.我希望能够在许多不同的页面上使用该功能.

I would like to write a function using jQuery to append a div to the end of a web page. I would like to be able to use the function on many different pages.

我已经编写了以下代码,但是不起作用:

I've written the following code, but it doesn't work:

    $(document).append('<div id="helloDiv"></div>');
    $('#helloDiv').html('hello'); // does nothing
    $('#helloDiv').css('top','100') // throws an error

我该如何解决?

推荐答案

附加到document毫无意义.而是附加到文档的body节点,因为这是所有可见内容所在的位置:

It is meaningless to append to the document. Append to the document's body node instead, since this is where all the visible content is:

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

这篇关于使用jQuery将div附加到文档末尾吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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