Home >Web Front-end >JS Tutorial >js implementation code for selecting multiple or single elements (using class)_javascript skills

js implementation code for selecting multiple or single elements (using class)_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:50:251198browse
Copy code The code is as follows:

function getElementsByClassName(elem_name,elem_tags) { //elem_name: Query class Name, elem_tags: under which element to search
if(elem_tags == null) {
elem_tags = '*';
}
var all_elem = document.getElementsByTagName(elem_tags);//Return one Element array
var arr = []; //Define an empty array to store the result
for(var i=0; iif(all_elem[i].className == elem_name) {
arr.push(all_elem[i]);
}
}
return arr; //Return this result array
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn