Execute a namespaced function from within html onclick - Javascript jQuery

Javascript examples for jQuery:Mouse Event

Description

Execute a namespaced function from within html onclick

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script> 
      <script type="text/javascript">
var app  = app || {};/*from w w  w .  java2s .  co  m*/
(function($) {
    app.hello = function() {
         console.log("hello");
    }
})(app, jQuery);

      </script> 
   </head> 
   <body> 
      <button onclick="app.hello()">Click me</button>  
   </body>
</html>

Related Tutorials