Latest Version: 2.0 RC 3 14 March 2017

Method _.nodeCountChildren


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

Calling Convention:
_.nodeCountChildren(Element[, nodeMask || tagName]]])
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.
A integer count of the number of matching DOM elements that are direct children of Element

Example #1


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


Console.log(_.nodeCountAll(_d.getElementById('test'))); // 2
Console.log(_.nodeCountAll(_d.getElementById('test'), 'p')); // 1

A result of 2 is reported by the first log entry because by default only nodeType 1 is matched and for direct children there's the div and the p. That inner DIV's contents don't count, to get that number use _.nodeCountAll. The single result for paragraphs is becuase there's only one paragraph as a direct child. Again the contents of that DIV don't count!