/ Published in: JavaScript
Derivative from Dustin Diaz's getElementsByClass
Expand |
Embed | Plain Text
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; }
You need to login to post a comment.
