Elementals.js

Latest Version: 3.0 RC 1 17 July 2017

Method _.Node.mask

Checks if the passed Element matches the passed mask or tagName.

Calling Convention:
_.Node.mask(Element[, node.mask || tagName])
Parameters:
Element
The Element to test.
node.mask 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 node.mask only elements of node type 1 with a matching tagName will be counted.
Returns:
Boolean true or false
Properties:

The following "constants" exist to aid in creating masks.

_.Node.mask.ELEMENT    = 0x0001; // nodeType 1
_.Node.mask.TEXT       = 0x0004; // nodeType 3
_.Node.mask.PROCESSING = 0x0040; // nodeType 7
_.Node.mask.COMMENT    = 0x0080; // nodeType 8
_.Node.mask.DOCUMENT   = 0x0100; // nodeType 9
_.Node.mask.DOCTYPE    = 0x0200; // nodetype 10
_.Node.mask.FRAGMENT   = 0x0400; // nodeType 11

Example

HTML

<div id="test"></div>

JavaScript

var test = document.getElementById('test');
console.log('#test is a Element node: ', _.Node.mask(test));
console.log('#test is a Element node (direct): ', _.Node.mask(test, _.Node.mask.ELEMENT));
console.log('#test is a Comment node: ', _.Node.mask(test, _.Node.mask.COMMENT));
console.log('#test is a DIV tag: ', _.Node.mask(test, 'div'));
console.log('#test is a UL tag: ', _.Node.mask(test, 'ul'));

Output

#test is a Element node: true
#test is a Element node (direct): true
#test is a Comment node: false
#test is a DIV tag: true
#test is a UL tag: false