Js gets the concrete implementation of the collection of elements by the element class name

  • 2020-03-30 01:16:04
  • OfStack

 
function getElementsByClassName(n) { 
var classElements = [],allElements = document.getElementsByTagName('*'); 
for (var i=0; i< allElements.length; i++ ) 
{ 
if (allElements[i].className == n ) { 
classElements[classElements.length] = allElements[i]; 
} 
} 
return classElements; 
} 

Related articles: