Lao Lao - 1 year ago 57
jQuery Question

How to check if the click was directly in an element or some of its children only?

I don't want clicks on children other than some, and the parent div itself to trigger any events.

Please see this, which does not do what I want:

$(document).ready(function() {

$('#parent').on('click', function(event) {
alert("you clicked directly on me!");


Answer Source

you can use

Example :

$(document).ready(function() {
  $("div").on("click", function(event) {
    alert("You click on : " +
<script src=""></script>
<div>this is Div
  <p>This is p</p>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download