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

  1363 views   2 years ago jQuery

Use the Property

You can use the property to get the ID of the element that fired an event in jQuery. This property always refers to the element that triggered the event.

The following example will display the name of the element that was just clicked.

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>jQuery Get the DOM Element that Initiated the Event</title>
    div, p, span{
        padding: 30px;
        display: block;        
        border: 3px solid #999;
<script src=""></script>
        alert("You've clicked: " + + ", id: " +;
    <div id="myDiv">
        <p id="myP">
            <span id="mySpan">Just click anywhere.</span>


Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]