[Project_owners] Finding Href

Karsten Düsterloh kd at tprac.de
Mon Aug 27 13:43:50 PDT 2007

joe ertaba aber hob zu reden an und schrieb:
> var target = e.target;
> while(target.href == undefined)
> target = target.parentNode;
> var href = target.href;
> it works good but it get error at line (while(target.href == undefined))
> when target is not a link: Error: target has no properties

You need to check that haven't passed the root node yet (whose
parentNode will be null) and you should use the "in" operator to check
for the href member instead of comparing against undefined:

var target = e.target;
while (target && !("href" in target))
  target = target.parentNode;
var href = target ? target.href : "";

       Freiheit stirbt        |       Fsayannes SF&F-Bibliothek:
            Mit Sicherheit    |       http://fsayanne.tprac.de/

More information about the Project_owners mailing list