Jquery Get Target Of Event

Jquery Get Target Of Event

Jquery Get Target Of Event.

Some times you need to find the target element of mouse click event. Here we will see how to get target element of mouse click. We have several elements inside a div container. When user clicks on any of the child element of container div, we get target element name.

HTML Source code:

<div>
    <div id="div1" style="height: 500px; width: 600px; background-color: blue">
        <p>User Click inside a tag:  </p>  
        <p id="paraTag">User Click inside a tag:  </p>  
        <h1>I'm h1 tag </h1>  
                      
         
    </div>
</div>

Jquery used to get target element name.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

   <script>
     
     $(document).ready(function(){
     
           $("#div1").click(function(e){            
             $("#paraTag").text(e.target.tagName);
             e.preventDefault();
             
     
           });
     
     });
     
   </script>

Tags:

How to get Jquery selected optionBasics of jqueryLearning JqueryJQuery Get Element By ID or class name or tag nameJQuery Get .next() ElementJquery textbox KeyUp eventGet Selected Value From Dropdownlist [JQuery]JQuery get Value Of TextareaJquery image click eventJquery button click eventJQuery Slide

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.