Tryit Editor v2.3

Edit This Code:
<!DOCTYPE html> <html> <head> <script src="loadxmldoc.js"> </script> </head> <body> <script> //check if the previous sibling node is an element node function get_previoussibling(n) { x=n.previousSibling; while (x.nodeType!=1) { x=x.previousSibling; } return x; } xmlDoc=loadXMLDoc("books.xml"); x=xmlDoc.getElementsByTagName("author")[0]; document.write(x.nodeName); document.write(" = "); document.write(x.childNodes[0].nodeValue); y=get_previoussibling(x); document.write("<br>Previous sibling: "); document.write(y.nodeName); document.write(" = "); document.write(y.childNodes[0].nodeValue); </script> </body> <!-- Mirrored from www.w3schools.com/dom/tryit.asp?filename=try_dom_previoussibling by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 23 Jan 2015 08:22:36 GMT --> </html>
Result:
Try it Yourself - © w3schools.com