<!DOCTYPE html > <html> <head> <meta charset="utf-8" /> <title>get objects by class</title> </head> <body > <div class="a">1</div> <div class="a">2</div> <div class="a">3</div> <div class="a">4</div> <script> getObjsByClass("a"); function getObjsByClass (param) { var tags = tags || document.getElementsByTagName("*"); var list = []; for( var k in tags) { var tag = tags[k]; if(tag.className == param) { document.write(tag.innerHTML); list.push(tag); } } return list; } </script> </body> </html>