The problem is not supported for getelementsbyclassname in JavaScript in IE 6/7/8.
Then the need to simulate the getelementsbyclassname needs to take the classname attribute, which involves the getattribute problem in JavaScript.
In IE 6/7, there is a bug for getattribute
Need to use ClassName to get the following:
var node = document.getElementById ("test"); var name = Node.classname;
For standard browsers, you can use classname directly or you can 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:
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;}
The implementation here is relatively simple.
1: General properties recommended: Node.xxx.
2: Custom Attribute recommended: Node.getattribute ("xxxx").
3: It is recommended to use Node.getattribute ("xxx"), such as for in the label, when getting the target is a keyword in JavaScript.
4: When acquiring the target is reserved word, such as: class, please use ClassName instead.
[JavaScript] Getelementsbyclassname with classname and getattribute!