title: Javascript get event id
body: <p>I am using Javascript and am creating my function within a closure, the problem I'm having is getting the id of the button the user has pressed.</p>
  
  <p>The following code works when not in the closure, but when I place it inside it doesn't seem to work.</p>
  
  <p>Please help, thanks in advance for any help.</p>
  
  <p>code to get id...</p>
  
  <pre><code>var id = event.target.id;
  </code></pre>
  
  <p>within closure...</p>
  
  <pre><code>var closure = (function(){
  
      var id;
  
      return{
           getId: function(){
  
               id = event.target.id;
  
           }
      };
  }());
  </code></pre>