Pass variable onclick event handler - Javascript DOM Event

Javascript examples for DOM Event:onclick

Description

Pass variable onclick event handler

Demo Code

ResultView the demo in separate window

<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>

Related Tutorials