Add function to Object with an element selector - Javascript jQuery

Javascript examples for jQuery:Tag Traversing

Description

Add function to Object with an element selector

Demo Code

ResultView the demo in separate window

<html lang="en">
 <body translate="no"> 
  <button class="exampleButton">Test</button> 
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 
  <script>
      function Object(name, button){
    this.name = name;/*from  w  w w.j  a v a2 s . c o  m*/
    this.button = button;
}
var ExampleOne = new Object('Example One', $('.exampleButton'));
ExampleOne.button.click(function(e) {
  console.log('success!');
});
    
      </script>  
 </body>
</html>

Related Tutorials