Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #28548

Re: Recursive function to find a node in the DOM

Path csiph.com!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From "Christoph M. Becker" <cmbecker69@arcor.de>
Newsgroups comp.lang.javascript
Subject Re: Recursive function to find a node in the DOM
Date Thu, 20 Aug 2015 02:11:24 +0200
Organization solani.org
Lines 40
Message-ID <mr35v5$1jf$1@solani.org> (permalink)
References <mo53os$am9$1@dont-email.me> <5530725.v0RXNFEj4j@PointedEars.de> <mq3qpn$nn$1@solani.org> <1885256.KGaLaWtVka@PointedEars.de> <mqdu4i$sbr$1@solani.org> <4738754.gQ6MLv009L@PointedEars.de> <mqj218$fvq$1@solani.org> <2800685.3l0yYTo2pD@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Trace solani.org 1440029477 1647 eJwFwYEBwCAMArCXrALtO2zD/09YwqPS2xAFXl5l+jOMHGa0VbsfLBXSpFVe8pS4w0D+AQtFEEA= (20 Aug 2015 00:11:17 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Thu, 20 Aug 2015 00:11:17 +0000 (UTC)
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0
X-User-ID eJwNysEBwCAIA8CVxIRQxqEi+4/Q3vscMp2gXPTxwbXoxczYaiyVHFls4hHOnPkruLvm+mupDwRTEIE=
In-Reply-To <2800685.3l0yYTo2pD@PointedEars.de>
Cancel-Lock sha1:LljheBlv8nBwgIqwUzw1n9Kqxu4=
X-NNTP-Posting-Host eJwFwYkRwDAIA7CVQnhcxiE+vP8IldLLiojKilTqwrtZ7VyTlq19D7GwM7x8MUB+Yk8eqvYHLU4SBg==
Xref csiph.com comp.lang.javascript:28548

Show key headers only | View raw


On 16.08.2015 at 08:48, Thomas 'PointedEars' Lahn wrote:

> I thought my illustration above in combination with what I said about the 
> property values under certaining conditions was, well, illustrative.  
> Perhaps you want to use a fixed-width font.  Simply handing out the 
> algorithm would defeat the purpose of the exercise.
> 
> […]  Try again.

Thanks for insisting. :)  Albeit this exercise still seems rather
somewhat academic to me, I found it interesting that it is indeed
possible to walk the DOM *tree* iteratively.  Apparently, I had
overlooked the Node::parentNode property which makes that possible.

A *simple* implementation of the iterative algorithm might be:

    function eachChildOf(baseNode, func) {
        var node = baseNode.firstChild;
        while (node) {
            func(node);
            if (node.firstChild) {
                node = node.firstChild;
            } else if (node.nextSibling) {
                node = node.nextSibling;
            } else {
                while (node.parentNode != baseNode &&
                        !node.parentNode.nextSibling) {
                    node = node.parentNode;
                }
                if (node.parentNode != baseNode) {
                    node = node.parentNode.nextSibling;
                } else {
                    break;
                }
            }
        }
    }

-- 
Christoph M. Becker

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-15 09:59 +0200
  Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-15 11:59 +0200
    Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-15 12:03 +0200
    Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-15 13:36 +0200
      Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-19 12:27 +0200
        Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-19 12:34 +0200
        Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-21 12:08 +0200
          Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-25 14:11 +0200
            Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-25 21:22 +0200
              Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-27 16:12 +0200
    Re: Recursive function to find a node in the DOM "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-08-08 04:50 +0200
      Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-08-08 09:33 +0200
        Re: Recursive function to find a node in the DOM "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-08-12 00:48 +0200
          Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-08-12 01:18 +0200
            Re: Recursive function to find a node in the DOM "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-08-13 23:26 +0200
              Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-08-16 08:48 +0200
                Re: Recursive function to find a node in the DOM "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-08-20 02:11 +0200
  Re: Recursive function to find a node in the DOM Scott Sauyet <scott.sauyet@gmail.com> - 2015-07-18 15:59 -0700
    Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-21 12:30 +0200
      Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-21 13:53 +0200
        Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-21 14:51 +0200
          Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-21 16:05 +0200
            Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-07-21 20:35 +0200
            Re: Recursive function to find a node in the DOM Scott Sauyet <scott.sauyet@gmail.com> - 2015-07-30 22:10 -0700
              Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-08-06 10:07 +0200
                Re: Recursive function to find a node in the DOM Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-08-06 20:15 +0200
                Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-08-08 01:21 +0200
        Re: Recursive function to find a node in the DOM Scott Sauyet <scott.sauyet@gmail.com> - 2015-07-30 22:09 -0700
  Re: Recursive function to find a node in the DOM Denis McMahon <denismfmcmahon@gmail.com> - 2015-07-29 03:04 +0000
    Re: Recursive function to find a node in the DOM "danca (Daniele Campagna)" <cyberdanny@tiscalinet.it> - 2015-08-06 10:20 +0200

csiph-web