I'm trying to understand how this function works. I know that it allows you to get the nextSibling element in a document but how? Anyone can explain what the 2 if statements are doing would be a great help.

function getNextElement(node) {
if(node.nodeType == 1) {
return node;
}
if (node.nextSibling) {
return getNextElement(node.nextSibling);
}
return null;
}