|
I rushed through it, but appears to work fine. Description: Basically, this code is a shortcut to tedious for...ifs when searching for elements. function forElements(a, b) { for(var i = document.getElementsByTagName("*"), x = 0; x < i.length; x ++) if(forHierarchy(i[x], a)) b(i[x]); } function forHierarchy(a, b) { for(var x in b) if(a[x] && b[x].constructor == Object) { if(!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: forElements({ className: "menubg", childNodes: { length: 3, 1: {} } }, function(a) { a.innerHTML = "Hello World"; });The above will check for any elements with class names of "menubg," childNodes.length of 3, and an existing childNodes[1] and set their innerHTML to "Hello World."
Last Edit: Jun 12, 2007 1:43:51 GMT by Aaron
|
|
|