I want to GET ID or class of the clicked element. Can someone give me idea how to do this? I tried to get the ID of the clicked element but it's not working. 
Here's my jquery.
$('.sems').click(function() { 
    var id = $(this).attr('id');
    alert(id);
});
Here's the full code where link is located.
if(isset($_POST['loadsem'])) {
    $stud = $_POST['stud'];
    $output = '';  
    $sql = "SELECT DISTINCT sch_year,semester FROM grades WHERE stud_no ='$stud'";
    $result = mysqli_query($con,$sql);
    $output .= '
                  <div class="table-responsive">
                    <table class="table table-bordered">
                      <tr>
                        <th>Semesters Attended</th>
                      </tr>';
      while($row = mysqli_fetch_array($result))
      {
        $sem = $row['semester'];
        $year = $row['sch_year'];
        $output .= '<tr>
                      <td><a href="#" class="sems" id="asd">'; <--- Here's the link
                    if($sem == "1"){
                      $output .= $row['semester']. "st Semester S.Y " .$row['sch_year'];
                    } else {
                      $output .= $row['semester']. "nd Semester S.Y " .$row['sch_year'];
                    }
                    $output .='</a></td>
                    </tr>';
      }
          $output .= '</table>
            </div>';
   echo $output;    
}
 
     
     
     
    