0

I created project demo from here

When I double click on element of children, so element of parent will be trigger on the same time. I don't want double click event on element of parent trigger, so everbody can help me? Thanks

    <style>
    #parent {
        width: 200px;
        height: 200px;
        position: relative;
        border: 1px solid black;
    }

        #parent:hover {
            cursor: pointer;
            background: green;
        }

    #children {
        width: 100px;
        height: 100px;
        position: absolute;
        top: 10px;
        left: 10px;
        border: 1px solid black;
    }

        #children:hover {
            cursor: pointer;
            background: blue;
        }
</style>
<div id="parent">
    <div id="children"></div>
</div>
<script>
    $('#children').dblclick(function () {
        alert('children');
    });
    $('#parent').dblclick(function () {
        alert('parent');
    });
</script>
Hieu Hoang
  • 3
  • 1
  • 3

1 Answers1

1

You need to use event.stopPropagation(); for child element.

 $('#children').dblclick(function (event) {
     event.stopPropagation();
     alert('children');
 });

You can learn more about it from following link. http://javascript.info/tutorial/bubbling-and-capturing

Harshal Sawant
  • 607
  • 3
  • 7