Javascript examples for DOM:Element getElementsByClassName
Get element by class name via getElementsByClassName() method
<html> <head> <meta name="viewport" content="width=device-width"> </head> <body> <button class="buttonClassName">click me</button> <script> function myFunc(){//w w w . j av a 2 s . c o m console.log("Got it"); } document.getElementsByClassName('buttonClassName')[0].onclick = myFunc; </script> </body> </html>