Optionally include root element with getElementsByTagName and querySelectorAll

My proposal is to add an optional boolean argument 'includeRoot' to the 
getElementsByTagName and querySelectorAll functions that are defined on 
DOM elements. This would make their use faster and cleaner in many 

Currently, when searching for elements in document sub-trees with either getElementsByTagName or querySelectorAll, it is not possible to potentially select the root element.
Hence, whenever code potentially needs to be applied to the root element as well, either code needs to be duplicated or a function needs to be created and called for each element in the returned list plus the root, which is either ugly or slow.

Example of a use case: 
A generalized cloneNode function that clones a document subtree and then clones the content of any contained canvas elements, including that of the root in case it is a canvas element.

Peter Sloetjes, Firefox add-on developer.

Received on Monday, 26 August 2013 00:11:10 UTC