【发布时间】:2011-07-11 13:40:10
【问题描述】:
我想使用 jQuery 编写一个函数,将 div 附加到网页的末尾。我希望能够在许多不同的页面上使用该功能。
我已经写了以下代码,但是它不起作用:
$(document).append('<div id="helloDiv"></div>');
$('#helloDiv').html('hello'); // does nothing
$('#helloDiv').css('top','100') // throws an error
我该如何解决这个问题?
【问题讨论】:
-
我认为这是因为您将其直接附加到文档中。尝试将其附加到 $('body')
-
谢谢大家!这个网站为我节省了很多时间和挫败感!
标签: javascript jquery dom