Interface Encapsulation: Package Document.getelementbyclassname () function
function Getelementsbyclassname (cname,domtag,root) {//functions have three parameters: the first parameter is the class name (required, string form); The second argument is the parent container (optional), the body node by default The third parameter is the tag name (string form) of the DOM node
if (root) {
root = typeof Root = = "string"? document.getElementById (root): root;
} else{
root = document.body;
};
Domtag = Domtag | | "*";
var els = root.getelementsbytagname (Domtag);
var arr = [];
for (var i = 0,n = els.length; i < n; i++) {
for (var j = 0,k = Els[i].classname.split (""), L = k.length; J < L; J + +) {
if (k[j] = = CName) {
Console.log (Els[i]);//This is the label of the output DOM element object
Return Els[i];els[i] is the DOM node object, appended to the array to save
Arr.push (Els[i]);
Break
}
}
}
Return arr;//returns the array, but the array is stored in a DOM element node, on the outside to call the node, with Arr[0] This method call can be
}
JS Native: Package Document.getelementbyclassname () function