Javascript examples for DOM Event:onclick
Pass variable onclick event handler
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){//from w w w . j av a 2 s . c o m var filename = 'testing'; document.getElementById('testdiv') .setAttribute('onclick', "console.log('" + filename + "')"); filename = 'more testing'; } </script> </head> <body> <div id="testdiv"> This is a test div </div> </body> </html>