How to use JQuery Event target Property

This article describe about jQuery Event target Property.
  • 2376

jQuery Event target Property

Which DOM (document object model) element triggered the event it is specified by the target property.

Syntax

event.target

 

Property Description
event Required. Define the event to check. That event parameter comes from bind method.

Example

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

    $(document).ready(function () {

        $("p, button, h1, h2").click(function (event) {

            $("div").html("Triggered by a " + event.target.nodeName + " element.");

        });

    });

</script>

</head>

<body>

<h1>This is a first heading</h1>

<h2>This is a second heading</h2>

<p>This is my first paragraph</p>

<button>This is first button</button>

<p>If headings, paragraphs and button element has a click.<br />And if you trigger one of the events, the div below will tell you which element triggered the event.</p>

<div />

</body>

</html>

 

Output


target event pic23.jpg


Note: In the above output you click on the button then output become


target event pic24.jpg


You may also want to read these related articles Click here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.