Skip to content

Instantly share code, notes, and snippets.

@nazomikan
Created October 10, 2011 07:09
Show Gist options
  • Save nazomikan/1274794 to your computer and use it in GitHub Desktop.
Save nazomikan/1274794 to your computer and use it in GitHub Desktop.
indexOfの単語マッチを上手に使う(sliceはnodelistにかけるとieで例外を出すの別途対応が必要のはず)
document.getElementsByClassName = function (needle) {
var allNodes = document.getElementsByTagName('*'),
nodes = Array.prototype.slice.call(allNodes),
outArray = [],
i,c,l;
for (i = 0, l = nodes.length; i < l; i++) {
if (nodes[i].hasAttribute("class")) {
c = " " + nodes[i].className + " ";
if (c.indexOf(" " + needle + " ") !== -1) {
outArray.push(nodes[i]);
}
}
}
return outArray;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment