How to get the next element using only JavaScript?
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 .prependChild() , .appendChild() , .innerHTML , etc. .innerHTML . properties and methods, but I'm looking for how to add (add) content after closing the </body> ?
I need this without using jQuery - is this possible?
+7
user1386320
source share 2 answers
If you use 'id'.you can use these properties:
document.getElementById('id').nextSibling; document.getElementById('id').previousSibling; +7
Amrendra
source share It will not work in any browser, because the content after the body not โlegalโ. In any case, it will be:
document.body.parentNode.appendChild(document.createTextNode('text after body')); document.body.parentNode.appendChild(document.createComment('comment after body')); http://jsfiddle.net/yVKk6/ and check the result frame.
+2
Roman
source share