GetElementsByAttribute
Sep 23, 2003Could be rewritten to work in ie5w, ie5m, of course, but I like it like it is:
// document.getElementsByAttribute([string attributeName],[string attributeValue],[boolean isCommaHyphenOrSpaceSeparatedList:false])
document.getElementsByAttribute=function(attrN,attrV,multi){
attrV=attrV.replace(/|/g,'|').replace(/[/g,'[').replace(/(/g,'(').replace(/+/g,'+').replace(/./g,'.').replace(/*/g,'*').replace(/?/g,'?').replace(///g,'/');
var
multi=typeof multi!='undefined'?
multi:
false,
cIterate=document.getElementsByTagName('*'),
aResponse=[],
attr,
re=new RegExp(multi?''+attrV+'':'^'+attrV+'$'),
i=0,
elm;
while((elm=cIterate.item(i++))){
attr=elm.getAttributeNode(attrN);
if(attr &&
attr.specified &&
re.test(attr.value)
)
aResponse.push(elm);
}
return aResponse;
}