Edit This Code:
<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
        myFunction(xhttp);
    }
};
xhttp.open("GET", "books.xml", true);
xhttp.send();

function myFunction(xml) {
    var xmlDoc = xml.responseXML;
    var x = get_previousSibling(xmlDoc.getElementsByTagName("price")[0]);
    document.getElementById("demo").innerHTML = x.nodeName;
}

function get_previousSibling(n) {
    var y = n.previousSibling;
    //check if the node is an element node
    while (y.nodeType != 1) {
        y = y.previousSibling;
    }
    return y;
}
</script>

</body>
</html>


Result:
Try it Yourself - © w3schools.com
Privacy Policy