Changes between Initial Version and Version 1 of Ticket #10213


Ignore:
Timestamp:
Oct 27, 2009, 2:59:43 PM (13 years ago)
Author:
Eugene Lazutkin
Comment:

Probably simpler (and more efficient) to do it using a loop rather than a straight recursion. As is the code doesn't work. And it uses this, which we try to avoid.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #10213

    • Property Owner changed from anonymous to sjmiles
    • Property Component changed from General to HTML
    • Property Summary changed from [Contribution] Searching the Ancestor Hierarchy for the first DOMNode.nodeName to [cla] Searching the Ancestor Hierarchy for the first DOMNode.nodeName
  • Ticket #10213 – Description

    initial v1  
    1 
    2 
    31{{{
    4         /**
    5          * Returns the first ancestor node found that has the
    6          * parentNodeName argument as the DOMNode.nodeName.
    7          */
    8         findAncestorNodeByName: function(/*String*/ ancestorNodeName, /*DOMNode*/ domNode)
    9         {
    10                 var ancestorNode =
    11                         domNode.parentNode;
    12                
    13                 if (ancestorNode != null)
    14                 {
    15                         if (ancestorNode.nodeName.toLowerCase() == ancestorNodeName.toLowerCase() )
    16                         {
    17                                 return ancestorNode;   
    18                         }
    19                         else
    20                         {
    21                                 this.findAncestorNodeByName(ancestorNodeName, ancestorNode);
    22                         }
    23                 }
    24         }
     2#!js
     3/**
     4 * Returns the first ancestor node found that has the
     5 * parentNodeName argument as the DOMNode.nodeName.
     6 */
     7findAncestorNodeByName: function(/*String*/ ancestorNodeName, /*DOMNode*/ domNode)
     8{
     9  var ancestorNode = domNode.parentNode;
     10  if (ancestorNode != null)
     11  {
     12    if (ancestorNode.nodeName.toLowerCase() == ancestorNodeName.toLowerCase() )
     13    {
     14      return ancestorNode;     
     15    }
     16    else
     17    {
     18      this.findAncestorNodeByName(ancestorNodeName, ancestorNode);
     19    }
     20  }
     21}
    2522}}}
    26