Skip to content

Instantly share code, notes, and snippets.

@silianlinyi
Created November 21, 2013 13:17
Show Gist options
  • Save silianlinyi/7581424 to your computer and use it in GitHub Desktop.
Save silianlinyi/7581424 to your computer and use it in GitHub Desktop.
定义getElementsByAttribute函数。它以一个属性名称字符串和一个可选的匹配值作为参数。
function getElementsByAttribute(att, value) {
var results = [];
iterateDOM(document.body, function(node) {
var actual = node.nodeType === 1 && node.getAttribute(att);
if(typeof actual === 'string' && (actual === value || typeof value !== 'string')) {
results.push(node);
}
});
return results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment