簡體   English   中英

在BODY結束之前移動元素

[英]Move element before the end of BODY

有沒有一種方法可以將html元素放置在我的body結束標簽之前,而又不知道在其之前? 在這種情況下,我不知道結尾處有ul列表。

注意 :我無法使用jquery解決此問題。

例如

<body>
   <p id="test">Hello</p>

   <script>
       document.getElementById("test").MOVE_BEFORE_BODY();   //<-- something like this
   </script>

   <ul>
     <li>...</li>
     <li>some random stuff</li>
   </ul>
   <!-- element should be moved to this position -->
</body>

someElement.appendChild會將元素移動到someElement的末尾。

document.body.appendChild(
    document.getElementById("test")
);

使用document.body.appendChild(yourElement)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM