Elementals.js

Latest Version: 3.7 Final 20 December 2018

Method _.Node.countAll

Summary:

Counts the number of elements inside the target element, using a nodeType or tagName mask.

Calling Convention:
_.Node.countAll(Element[, nodeMask || tagName])
Parameters:
Element
The target Element to count the nodes inside of.
nodeMask optional

A bitwise mask used to filter the results. See the Node Masking page for more information.

If omitted, a mask of 1 (matching for nodeType 1) is used.

tagName optional
A tagName to match. When used instead of a nodeMask only elements of node type 1 with a matching tagName will be counted.
Returns:
A integer count of the number of matching DOM elements inside Element

Example #1

JavaScript

<div id="test">
	<div>
		<h2>Section 1</h2>
		<p>This is a <strong>test</strong></p>
		<p>This is another paragraph</p>
	</div>
</div>

JavaScript

Console.log(_.Node.countAll(_d.getElementById('test'))); // 5
Console.log(_.Node.countAll(_d.getElementById('test'), 'p')); // 2

A result of 5 is reported by the first log entry because by default only nodeType 1 is matched, and there are four tags TOTAL inside div#test. A result of 2 is reported by the second logging since we're only checking for paragraphs.