Inside onClick to get reference to function and hardcoded parameters - Javascript DOM Event

Javascript examples for DOM Event:onclick

Description

Inside onClick to get reference to function and hardcoded parameters

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <button id="my-button" onclick="test('hello world')"> TEST </button> 
      <button onclick="triggerTest()"> TRIGGER TEST </button> 
      <script type="text/javascript">
function test(word) {// w  w  w  . j a  v a2  s  .  co m
  console.log(word);
}
function triggerTest() {
   var tempClick = document.querySelector('#my-button').onclick;
  tempClick.call(tempClick);
}

      </script>  
   </body>
</html>

Related Tutorials