Skip to content

Instantly share code, notes, and snippets.

@poying
Last active December 19, 2015 10:39
Show Gist options
  • Save poying/5942514 to your computer and use it in GitHub Desktop.
Save poying/5942514 to your computer and use it in GitHub Desktop.
var getElementsByAttribute = function (tagname, attr, value) {
if (arguments.length < 3) {
value = attr;
attr = tagname;
tagname = '*';
}
var match = [];
var eles = document.getElementsByTagName(tagname);
var i = eles.length;
while (i) {
i -= 1;
if (eles[i].hasAttribute(attr)) {
if (!value || eles[i].getAttribute(attr) === value) {
match.push(eles[i]);
}
}
}
return match;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment