开发者

Add a node before a closing tag?

开发者 https://www.devze.com 2022-12-10 15:07 出处:网络
What\'s the best way to insert an element into a page\'s HEAD directly before the closingtag using JavaScript?

What's the best way to insert an element into a page's HEAD directly before the closing tag using JavaScript?

...<HEAD>
<script>...</script>
<script>...</script>
<script>...</script>
<link .../>
<开发者_如何学运维;link .../>
<link title="MY NEW LINK ELEMENT" />
</HEAD>...

I know about the ol' insertBefore(sp1, sp2.nextSibling) trick, but that just lets you drop something after a closing tag.


If you're doing straight JavaScript, it's called appendChild. jQuery has a wrapper called append. Prototype has insert which appends when not given a location.

0

精彩评论

暂无评论...
验证码 换一张
取 消