How to Get the ID of the Element that Fired an Event in jQuery

There is a simple method that is used to get the ID of the element that fires an event.

The property is designed to get the ID of the element that fired an event in jQuery:

<!DOCTYPE html>
    <title>Title of the Document</title>
      div,p,span {
        padding: 30px;
        display: block;
        border: 3px solid green;
    <script src=""></script>
    <div id="divId">
      <p id="pId">
        <span id="spanId">Click anywhere.</span>
      $(document).ready(function() {
          $(document).click(function(event) {
              alert("Clicked: " + + ", id: " +;

The “this” keyword will also work, however, it is not a jQuery object, so to use a jQuery function on it, you must refer to it as $(this):

$(document).ready(function () {
  $("a").click(function (event) {
    // this.append will not work

The target property is a reference to the object that dispatched the event. It is often useful to compare to this to determine if the event is being handled due to event bubbling. This keyword refers to an object which is executing the current bit of JavaScript code.