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
Release: 2016-05-16 17:50:25
Original
1196 people have browsed it
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
}
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template