Return to Snippet

Revision: 3621
at August 23, 2007 06:47 by micmath


Initial Code
function getPrevious(el) {
	function isIgnorable(node) {
		// is a comment or contains only whitespace
		return (node.nodeType == 8 || /^[\t\n\r ]+$/.test(node.data));
	}

	var prev = el;
	while (prev = prev.previousSibling) {
		if (!isIgnorable(prev)) break;
	}

	return prev;
}

Initial URL

                                

Initial Description
This ignores whitespace and comments.

Initial Title
Get previous node.

Initial Tags

                                

Initial Language
JavaScript