This article mainly introduces how to use native JS to obtain CLASS objects. Friends who have read dom programming art may know that it is the most commonly used .... I think of dom programming art.
Untitled document Sss
Script function getElementsClass (classnames) {var classobj = new Array (); // defines the Array var classint = 0; // defines the Array subscript var tags = document. getElementsByTagName ("*"); // obtain all HTML tags for (var I in tags) {// traverse tags if (tags [I]. nodeType = 1) {// determine the node type if (tags [I]. getAttribute ("class") = classnames) // identifies and requires the same CLASS name, and forms an array {classobj [classint] = tags [I]; classint ++ ;}}return classobj; // returned array} // The following is the var a = getElementsClass ("ca"); a [0]. onclick = function () {alert ("");} a [1]. innerHTML = 'Here we are '; script
Sometimes multiple dom classes are the same and can be processed as follows:
The Code is as follows:
Var a = getElementsClass ("ca ");
For (var I = 0; I (function (I ){
Alert (a [I])
}) (I)
}
If there are multiple identical classes, you can use them together. If you want to achieve JQ, you can directly click the class. You also need to do some complicated processing.