title: Getting id of an element in jQuery using a function
body: <p>I have a simple code with two buttons in a div container. I want to get the id of a button using a function.</p>
  
  <p><strong>Problem</strong>: Can someone please explain why clicking on Button1 doesn't alert <code>myButton1</code>? How can I solve this issue?</p>
  
  <p><strong>Code</strong>:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
      &lt;style type="text/CSS"&gt;
          #mydiv{
              border: 1px dashed blue;
              width: 100px;
              height: 100px;
          }
      &lt;/style&gt;
      &lt;div id="myDiv"&gt;
          &lt;input type="button" id="myButton1" value="Button1"&gt;&lt;/input&gt;
          &lt;input type="button" id="myButton2" value="Button2"&gt;&lt;/input&gt;
      &lt;/div&gt;
  
      &lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="code.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>code.js</strong> :</p>
  
  <pre><code>myfunction = function(e){
      alert(this.id);
      e.stopPropagation();
      }
  
  $('#myDiv').click(function(){
              alert($('#myDiv').attr('id'));
          });
  
  $('#myButton1').click("myfunction()");
  
  $('#myButton2').click(function(e){
              alert(this.id);
              e.stopPropagation();
          });
  </code></pre>