|
Post by Schubaltz on Jun 13, 2007 9:15:05 GMT -5
I got the idea from my forElements...do snippet. If you can do a search on that scale with that script, why limit it?
Description: Takes getElementsByAttr() a bit further, allowing you to check for childNodes and attributes of childNodes.
Syntax: getElementsByHrc(string, {,attributes})
function getElementsByHrc(a, b) { var n = []; for(var i = document.getElementsByTagName(a), x = 0; x < i.length; x ++) if(forHierarchy(i[x], a)) n.push(i[x]); return n; } function forHierarchy(a, b) { for(var x in b) if(a[x] && b[x].constructor == Object) { if(!this.forHierarchy(a[x], b[x])) return false; } else if((b[x].constructor == RegExp ? !a[x].match(b[x]) : a[x] != b[x])) return false; return true; }
Example: var i = getElementsByHrc("td", { className: "catbg", firstChild: { nodeName: "B" }) for(var x = 0; x < i.length; x ++) i[x].innerHTML += "lol";
The above will insert the text "lol" into any TD elements with classNames of "catbg" and firstChilds with nodeNames of B.
|
|