event.target
PropertyYou can use the event.target
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">
<head>
<meta charset="utf-8">
<title>jQuery Get the DOM Element that Initiated the Event</title>
<style>
div, p, span{
padding: 30px;
display: block;
border: 3px solid #999;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
$(document).click(function(event){
alert("You've clicked: " + event.target.nodeName + ", id: " + event.target.id);
});
});
</script>
</head>
<body>
<div id="myDiv">
<p id="myP">
<span id="mySpan">Just click anywhere.</span>
</p>
</div>
</body>
</html>
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]
How To Set up SSH Keys on a Linux Server
SSH or Secure Shell is network protocol...How to Connect MySQL Database in Python?
In this article, I will share with you h...How to Check If an Input Field is Empty Using jQuery
Use the jQuery val() Method...Laravel 8 - jQuery Ajax File Upload with Progress Bar Tutorial
In this article, i will share with you h...Install Python 3.8 in Ubuntu
Python is flexible and powerful open-sou...