Report abuse


			
var library = {
	/**
	 * Locates nodes by their attribute values
	 * 
	 * @param  {String} attribute
	 * @param  {String} value
	 * @param  {String|HTMLElement} parent
	 * @param  {String} nodeName
	 * @return {Array}
	 */
	getElementsByAttribute : function (attribute, value, parent, nodeName, looseMatch) {
		parent     = this.getElement(parent || document);
		nodeName   = nodeName || '*';
		looseMatch = !!looseMatch;
		
		var out  = [];
		var nodeList = parent.getElementsByTagName(nodeName);
		
		for (var i = 0; i < nodeList.length; i++) {
			if (attribute === 'class') {
				var attributeValue = nodeList[i].className;
			}
			else {
				var attributeValue = nodeList[i].getAttribute(attribute);
			}
			
			if (looseMatch) {
				var isAMatch = (attributeValue.indexOf(value) > -1);
			}
			else {
				var isAMatch = (attributeValue === value);
			}
			
			if (isAMatch) {
				out.push(nodeList[i]);
			}
		}
		
		return out;
	}
}