The id may be undefined rather than '' so it's best to test this way:
while (targ.parentNode && targ.parentNode.id &&
meaning that "it has an id" other than any of undefined, '', null, void.
Off topic, but it is preferable to declare arrays like this:
var tagx = ['BODY', 'P', 'LI', 'A'];
Your current code will skip some links. Where you have LI > A followed by an UL, clicking a link in the UL will not find the first A-link (assuming this is your intent?) as it is not a parent-element.
If you wish to search other than through the direct parent-heritage then you might consider jQuery. Using jQuery it is much easier to obtain, and navigate, siblings() and parents(), etc. It would still, however, prove a challenge to navigate reliably/consistently.
I haven't come across tagNode(?) - nodeName
For your sample code your LI's need to have IDs to continue the search.