Created
October 10, 2011 07:09
-
-
Save nazomikan/1274794 to your computer and use it in GitHub Desktop.
indexOfの単語マッチを上手に使う(sliceはnodelistにかけるとieで例外を出すの別途対応が必要のはず)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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