title: Getting the id of the anchor tag which was clicked
body: <p>This is a list representation of data which is coming from a php database.The list is fetched using a foreach php loop and the data inside the achor tag is populated accordingly. </p>
  
  <pre><code>&lt;?php foreach($array as $iterate):?&gt;
   &lt;div class="col-sm-3"&gt;
    &lt;div class="panel panel-default"&gt;
     **&lt;a onClick='theFunction();' id="hello" href="#myModal" style="text-decoration:none;"&gt;**
      &lt;div class="panel-heading"&gt;
       &lt;img src ="audi_sillhouete.jpg" style="height:100%; width:100%;"&gt;
         &lt;p id="10" style="position:absolute; top:10%; padding-left:5%; padding-right:15%;"&gt;&lt;?php echo $iterate-&gt;test_name ?&gt;&lt;/p&gt;
      &lt;/div&gt;
     &lt;/a&gt;                    
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;?php endforeach;?&gt;
  </code></pre>
  
  <p>As you can see here, inside the anchor tag i have href-ed it to a modal box which will show a message whenever the user clicks on any of the link. There is a button in the modal window which will take the user to a different page. 
  The issue is that i want to pass certain value along with the url, but cannot do so as the link to the next page is defined in the modal window specification part. 
  So i came up with this solution. I thought of using the id attribute of the anchor tag, I tried to get the id attribute of the anchor which was clicked using javascript. </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
   function theFunction()
   {
      var id = $('a', this).attr('id');
      alert(id);
   }&lt;/script&gt;
  </code></pre>
  
  <p>From this i wanted to initialize a php variable and then use that php variable to pass as value in the href of the modal window button. But the value i am getting in the alert box is 'undefined' for some reason. I have tried all possible combinations of this. </p>
  
  <pre><code>$('a',this).attr('id');
  $this.id;
  </code></pre>
  
  <p>Everything return 'undefined'. </p>
  
  <p>Reference-This is the code for the modal window part.</p>
  
  <pre><code>&lt;div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"&gt;
    &lt;div class="modal-dialog"&gt;
      &lt;div class="modal-content"&gt;
        &lt;div class="modal-header"&gt;
          &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
          &lt;h4 class="modal-title"&gt;Instructions&lt;/h4&gt;
        &lt;/div&gt;
        &lt;div class="modal-body"&gt;
         Your test is about to commence. A timer will be initiated after the moment you start the test. You may choose to answer a question, or leave it empty. You can also attempt the questions in any order that you find suitable.&lt;br&gt;&lt;br&gt;Upon completion of the test, click on "Submit" to see your performance statistics.&lt;br&gt;&lt;br&gt;&lt;br&gt;Good luck!
        &lt;/div&gt;
        &lt;div class="modal-footer"&gt;
          &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
          &lt;a href="../test/pretest.php?test=&lt;?php echo $testname?&gt;" style="text-decoration:none;color:white;"&gt;&lt;button type="button" class="btn btn-primary"&gt;Continue&lt;/button&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;&lt;!-- /.modal-content --&gt;
    &lt;/div&gt;&lt;!-- /.modal-dialog --&gt;
  &lt;/div&gt;&lt;!-- /.modal --&gt;
  </code></pre>