Does .previousSibling always return the parent's text node if it exists?
No. It returns the immediately preceding sibling. In your case, there is a text node (a new line) immediately preceding the a
element, so it returns that.
If you remove the white space it should work as expected:
However, that's not a particularly nice solution. See @Esailija's answer for a nicer one!