// from snipplr.com code snippets // http://snipplr.com/view/28115/getelementsbyattribute/ // Derivative from Dustin Diaz's getElementsByClass document.getElementsByAttribute = function( attrib, value, context_node, tag ) { var nodes = []; if ( context_node == null ) context_node = this; if ( tag == null ) tag = '*'; var elems = context_node.getElementsByTagName(tag); for ( var i = 0; i < elems.length; i += 1 ) { if ( value ) { if ( elems[i].hasAttribute(attrib) && elems[i].getAttribute(attrib) == value ) nodes.push(elems[i]); } else { if ( elems[i].hasAttribute(attrib) ) nodes.push(elems[i]); } } return nodes; }