Javascript examples for DOM:Document getElementsByClassName
Get multiple elements using getElementsByClassName
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=( function() {//from www .j av a 2 s .com var elements = document.getElementsByClassName("test"); var names = ''; for(var i=0; i<elements.length; i++) { names += elements[i].name; } document.write(names); }); </script> </head> <body> <a class="test" name="Name 1"></a> <a class="test" name="Name 2"></a> <a class="test" name="Name 3"></a> </body> </html>