No reason. Just felt more natural to me . But now that I think about it a loop 
would perform much better than expensive function calls on a potentially messy 
DOM. 

But in this case the recursion will suffice :)

Sent from my iPhone

On 9 May 2011, at 16:14, Bryan Forbes <[email protected]> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On 5/9/11 7:31 AM, Mark McDonnell wrote:
>> Hi,
>> 
>> I have the following code...
>> 
>> function findParentElementWhichIs(startingPoint, elem) {
>> 
>>   var parent = startingPoint.parentNode,
>> 
>>     parentname = parent.nodeName.toLowerCase();
>> 
>> 
>> 
>>   if (parentname === 'body') {
>> 
>>    return false;
>> 
>>   }
>> 
>> 
>> 
>>   if (parentname === elem) {
>> 
>>    return parent;
>> 
>>   } else {
>> 
>>    findParentElementWhichIs(parent, elem);
>> 
>>   }
>> 
>>  }
>> 
> 
> Is there any reason you're recursing rather than just looping?
> 
> function findParentElementWhichIs(start, elemName){
>    var parent, parentName;
>    while(parent = start.parentNode){
>        parentName = parent.nodeName.toLowerCase();
>        if(parentName == elemName){
>            return parent;
>        }
>    }
>    return null;
> }
> 
> - -- 
> Bryan Forbes
> http://www.reigndropsfall.net
> 
> GPG Fingerprint
> 3D7D B728 713A BB7B B8B1  5B61 3888 17E0 70CA 0F3D
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.11 (Darwin)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iEYEARECAAYFAk3IBPAACgkQOIgX4HDKDz1LogCgpmYK8AcotMgGF7KOwCWxSuQD
> L+gAoJ/WXGWqFfNtmND8bjYlLcJXcBtY
> =OrGS
> -----END PGP SIGNATURE-----
> 
> -- 
> To view archived discussions from the original JSMentors Mailman list: 
> http://www.mail-archive.com/[email protected]/
> 
> To search via a non-Google archive, visit here: 
> http://www.mail-archive.com/[email protected]/
> 
> To unsubscribe from this group, send email to
> [email protected]

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to