In the DOM3 has joined the Getelementsbyclassname this method, however IE9, 10 other versions are not supported, this is a piece of pain!
This can be resolved so far, that the browser does not support this method, if the support does not matter, if not supported, in the Document object to add Getelementsbyclassname this method, such a writing has the advantage that no matter whether there is no native function you do not have to modify the code.
Some people on the Web directly define a getelementsbyclassname function, but in this case, all the use of document.getelementsbyclassname in the code should be rewritten as getelementsbyclassname. It's a bit inconvenient and not universal.
The following method perfectly supports document writing:
if (!document.getelementsbyclassname) {
document.getelementsbyclassname = function (ClassName, Element) {
var Children = (Element | | document). getElementsByTagName (' * ');
var elements = new Array ();
For (Var i=0. i<children.length; i++) {
var child = Children[i];
var classnames = Child.className.split (');
for (Var j=0 j<classnames.length; J + +) {
if (classnames[j) = = className) {
elements.push (child);
break;
}
}} return elements;}