admin管理员组文章数量:1243138
Let's say we have this markup:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8" />
<title>project.js</title>
<script src="project.js"></script>
<script>
</script>
</head>
<body>
<h1>some project — javascript & html tests</h1>
<hr />
<p>
testing 123
</p>
</body>
</html>
I know that there are .prependChild()
, .appendChild()
, .innerHTML
, etc, properties and methods, but what I am looking for is how to add (append) contents after the </body>
tag closure?
I need this, without using jQuery — is it possible?
Let's say we have this markup:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8" />
<title>project.js</title>
<script src="project.js"></script>
<script>
</script>
</head>
<body>
<h1>some project — javascript & html tests</h1>
<hr />
<p>
testing 123
</p>
</body>
</html>
I know that there are .prependChild()
, .appendChild()
, .innerHTML
, etc, properties and methods, but what I am looking for is how to add (append) contents after the </body>
tag closure?
I need this, without using jQuery — is it possible?
Share Improve this question asked Mar 8, 2013 at 8:45 user1386320user1386320 5-
I think most browser would not let you create an invalid DOM through DOM functions. (
html
can only contain 1head
and 1body
element and ment nodes. Nothing else.) – Roman Commented Mar 8, 2013 at 8:56 -
so meaning.. if I want to add something
after body
I should just then append the parent:html
tag? – user1386320 Commented Mar 8, 2013 at 8:57 - @ZlatanO. What do you want to add?! – Matías Fidemraizer Commented Mar 8, 2013 at 8:58
-
no.. that means if you try to add anything other than ments after the body tag, the browser will either ignore it or append it to
body
. – Roman Commented Mar 8, 2013 at 8:59 -
@MatíasFidemraizer - sorry matias, for not answering your question.. I've seen now that we can add scripts:
appended or prepended to **head**
orappended or prepended to **body**
.. I'm making a script loader – user1386320 Commented Mar 8, 2013 at 9:02
2 Answers
Reset to default 8If you use 'id'.you can use these property:
document.getElementById('id').nextSibling;
document.getElementById('id').previousSibling;
It won't work in some browser because content after body
is not "legal". Anyway, this would be:
document.body.parentNode.appendChild(document.createTextNode('text after body'));
document.body.parentNode.appendChild(document.createComment('ment after body'));
http://jsfiddle/yVKk6/ and inspect the Result frame.
本文标签: prependHow to get next element using JavaScriptonlyStack Overflow
版权声明:本文标题:prepend - How to get next element using JavaScript-only? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740089988a2223941.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论