W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2013

Re: Native DOM way to get nodes of arbitrary type/name

From: Bjoern Hoehrmann <derhoermi@gmx.net>
Date: Sat, 05 Oct 2013 12:12:23 +0200
To: Marat Tanalin <mtanalin@yandex.ru>
Cc: www-dom@w3.org
Message-ID: <k6pv491uio67i0knsccdkiggbcni4morbh@hive.bjoern.hoehrmann.de>
* Marat Tanalin wrote:
>It would be nice to have a native (usable and performant) DOM way for 
>retrieving DOM nodes by node type (or, alternatively, by node name).
>This could be represented by these two simple methods:
>    * element.getNodesByType(type) -- to get _all_ nodes
>      of specified type contained in the element
>      (like `element.getElementsByTagName('*')` for elements);

Use XPath, the convenient API would have it


but in some browsers you have to use the DOM Level 3 XPath methods,
which are slightly less convenient. Note in particular that XPath
allows you to use predicates to select a subset of "all" the nodes
that would otherwise be returned.

>    * element.getChildNodesByType(type) -- to get _direct child_
>      nodes of the element that have the specified type
>      (like `element.children` for elements).

Drop the `.//` in the paths above for this.
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 
Received on Saturday, 5 October 2013 10:12:50 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:21 UTC