[Project_owners] Finding Href
Karsten Düsterloh
mnenhy at tprac.de
Mon Aug 27 13:44:14 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 : "";
Karsten
--
Feel free to correct my English. :)
More information about the Project_owners
mailing list