Links

Javascript function for getting page elements by their attribute

function getElementsByAttribute(TagName,Attribute,Value)
{
var oElm = document.body;var oCurrent;var oAttribute;var arrReturnElements = new Array();
var arrElements = (TagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(TagName);
var oAttributeValue = (typeof Value != "undefined")? new RegExp("(^|\\s)" + Value + "(\\s|$)") : null;
for(var i=0; i 0)if(typeof Value == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute)))arrReturnElements.push(oCurrent);}
return arrReturnElements;
}

Post a Comment