可能重复:
Position an element from the end of the document at the top of the page的JavaScript - 移动从文件末尾一个元素刚过<body>
嗨
<div id="debug">
blabla
</div>
</body>
我如何可以移动#调试div在文件开头之后,<body>
之后,只用javascript?
可能重复:
Position an element from the end of the document at the top of the page的JavaScript - 移动从文件末尾一个元素刚过<body>
嗨
<div id="debug">
blabla
</div>
</body>
我如何可以移动#调试div在文件开头之后,<body>
之后,只用javascript?
试试这个:
var elem = document.getElementById('debug');
var body = document.body;
body.insertBefore(elem, body.firstChild);
演示:http://jsfiddle.net/ThiefMaster/BuAau/
如果您有jQuery的可用:
$('#debug').prependTo('body');
Javascript或jQuery的?在jQuery的使用:
$('body').append($('#debug'));
var element = document.getElementById('debug');
document.body.insertBefore(element, document.body.firstChild);
为什么张贴重复?你总是可以编辑你的文章(http://stackoverflow.com/questions/4814007/css-position-a-element-from-the-end-of-the-document-at-the-top-of-the-page/4814027#4814027)提供更多信息? – Chandu 2011-01-27 08:26:31
我以为人们会忽略它,因为它最初被标记为css :) – Alex 2011-01-27 08:30:29