Examples of stopping bubbling in JavaScript and examples of javascript bubbling
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Title> qypt15 </title>
<Style>
Div {
Background-color: green;
Border: 1px solid;
Padding: 50px;
}
</Style>
</Head>
<Body>
<P> the instance demonstrates the difference between bubble and capture when different event listeners are added. </P>
<Div id = "myDiv" onclick = "myDiv ()">
<P id = "myP" onclick = "myP ()"> click the section and I am a bubble. </P>
</Div> <br>
<Div id = "myDiv2" onclick = "myDiva ()">
<P id = "myP2" onclick = "myPa ()"> click the section, I am capturing. </P>
</Div>
<Script>
Function myP (e ){
Alert ("You clicked the P element! ");
Window. event? Window. event. cancelBubble = true: e. stopPropagation ();
}
Function myDiv (){
Alert ("You clicked the DIV element! ");
}
Function myPa (){
Alert ("You clicked the P2 element! ");
}
Function myDiva (){
Alert ("You clicked the DIV2 element! ");
}
</Script>
</Body>
</Html>