# JavaScript, Event bubbling, stopPropagation()

**URL:** <https://forum.kirupa.com/t/javascript-event-bubbling-stoppropagation/639398>\
**Category:** programming\
**Created:** [February 12, 2019, 7:07am UTC](https://forum.kirupa.com/t/javascript-event-bubbling-stoppropagation/639398 "2019-02-12T07:07:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shuvajit\_Mohanty](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@Shuvajit\_Mohanty](https://forum.kirupa.com/u/Shuvajit_Mohanty)\
**Post date:** [February 12, 2019, 7:07am UTC](https://forum.kirupa.com/t/javascript-event-bubbling-stoppropagation/639398/1 "2019-02-12T07:07:29Z")

</div>

```auto
<html>
<head>
    <style type="text/css">
        .divStyle
        {
            display: table-cell;
            border: 5px solid black;
            padding: 20px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div id="DIV1" class="divStyle" onclick="divA()">
        DIV 1
        <div id="DIV2" class="divStyle" onclick="divB()">
            DIV 2
            <div id="DIV3" class="divStyle" onclick="divC()">
                DIV 3
            </div>
        </div>
    </div>
    <script type="text/javascript">
        function divA(e)
        {
        alert("div1")
		e.stopPropagation();        
        }
        function divB(e)
        {
        alert("div2");
		e.stopPropagation();        
        }
        function divC(e)
        {
        alert("div3")
		e.stopPropagation();        
        }
    </script>
</body>
</html>

```

for me this `stopPropagation()` is not working please help me

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [February 12, 2019, 4:48pm UTC](https://forum.kirupa.com/t/javascript-event-bubbling-stoppropagation/639398/2 "2019-02-12T16:48:51Z")

</div>

You’re calling your event handlers without passing in the event object. If you check your console, you should see errors complaining about how `e` is not defined.

To fix this, pass the special `event` variable in the `onclick` attributes to each of your functions. This will then be assigned to their `e` parameters when called.

```auto
onclick="divA(event)"

```
