JavaScript, Event bubbling, stopPropagation()


#1
<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


#2

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.

onclick="divA(event)"