The problem is not supported for getelementsbyclassname in JavaScript in IE 6/7/8.
Then the need to simulate the getelementsbyclassname need to use the ClassName attribute, which involves JavaScript getattribute problem.
In IE 6/7, there is a bug for getattribute
It is necessary to use ClassName to obtain such as the following:
var node = document.getElementById ("test"); var name = Node.classname;
For standard browsers, the ability to use ClassName directly can also use Getattritbute, as a result:
Node.getattritbute ("class");
However, if it is IE 6/7, there is a problem with getattribute ().
So getelementsbyclassname can use the following methods, for example:
Getelementsbyclazzname = Document.getelementsclassname? function (name) {return document.getelementsclassname (name);}:function (name) {var nodes = document.getElementsByTagName ("*"), result = [];for (var node in nodes) {if (Node.classname && Node.className.indexOf (name)) {Result.push (node);}} return result;}
This is a simpler way to implement.
1: General properties recommended: Node.xxx.
2: Own definition attribute recommended: Node.getattribute ("xxxx").
3: It is recommended to use Node.getattribute ("xxx") when getting the target of keyword in JavaScript. such as the for in the label.
4: When acquiring the target is reserved word, such as: class, please use ClassName instead.
[JavaScript] Getelementsbyclassname with classname and getattribute!