To access outside of <html>, use document.documentElement.previousSibling document.documentElement.nextSibling Note that the node right above <html> is <!doctype html>