Elementals.js

Latest Version: 3.7 Final 20 December 2018

Method _.Node.prev

Similar to Element.previousSibling, this finds the previous sibling node matches the passed mask, or the previous Element node if a mask is omitted.

The reason to do this instead of previousSibling is that first, you can match by tagName. Second, there are other types of nodes that can end up on the DOM beside element... such as text nodes, comment nodes, etc.

Calling Convention:
_.Node.prev(Element[, nodeMask || tagName])
Parameters:
Element
The Element to find the previous sibling that matches the mask.
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:
The matching element, or false if no match found.

Example

HTML

<ul>
	<li>First</li>
	<li id="test">Second</li>
	<li>Third</li>
</ul>

JavaScript

var test = document.getElementById('test');
Console.log(_.Node.text(_.Node.prev(test)));

Will output "First"